Discussion:
[bottlepy] Need Help in Bottle module usage -- Returning static page
Syafiq Dosuki
2015-10-28 08:45:18 UTC
Permalink
I'm new in this. I have a question here and hope you can help me.

When requesting /list_10-20.html, I want to make python server to open
static file as shown below, parse it and by using template render requested
lines (for example lines 10-20) and return the rendered web page. The file
shown below is in json format.

{
"lines": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23
]
}


------------------------------
-------------------------------------------------------------------------------------------------------------

So the web page should look like:

10

11

12

13

14

15

16

17

18

19


So, is there any way bottle can help me in this?
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'gNeandr' via bottlepy
2015-10-28 14:56:04 UTC
Permalink
/list?10,20
@app.route('/list')
caller = request.fullpath[1:]
qString = request.query_string.strip()
print (" /"+caller + " >>" + qString + "<<")
This way you have the requested lines and then you need to parse the
JSON for the those lines.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ia n
2015-11-03 00:10:20 UTC
Permalink
Some confusion may arise with the term 'static file' . This in web
frameworks is normally a file sent from the server to the web client
(usually to a web browser) in the same form that the file is stored on the
host.

Your json file is a data file used by the server to prepare a dynamic
page. You do not say if the goal is have a html page or a json file sent
from bottle, but as you mention a template, I assume you wish to serve an
html page.

In makeing your case simple, it become a little unclear what you are trying
to do. To have a page return the output as stated, there is no reason for
your json file at all.
But your json file, if read an parsed would create a dictionary containing
the list 'lines' and lines would have the numbers 1 to 23 in a list.

In the example, you wish to return enties 10 through 20, which confusingly
are simply the number 10..20 (excluding the 20) which makes it unclear why
have the json at all.

@gNeandr posted a solution to collecting the arguments '10' and '20' to
your page.
simply take 'qString' and have:

num1,num2=[int x for x in qString.split(',')
return render(page,lines =lines[num1-1, num2-1])

your template file 'page' would then have a for loop (for line in lines)
and print each number.
If you need more then please ask


You would use the argument .
Post by Syafiq Dosuki
I'm new in this. I have a question here and hope you can help me.
When requesting /list_10-20.html, I want to make python server to open
static file as shown below, parse it and by using template render requested
lines (for example lines 10-20) and return the rendered web page. The file
shown below is in json format.
{
"lines": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23
]
}
------------------------------
-------------------------------------------------------------------------------------------------------------
10
11
12
13
14
15
16
17
18
19
So, is there any way bottle can help me in this?
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...