Web development with Python 3.1
Dotan Cohen
dotancohen at gmail.com
Wed Oct 28 15:38:37 EDT 2009
>> It
>> did not look like I had any control over the tags at all.
>
> I can tell you you have full control over the whole HTTP response's content
> and headers. And FWIW, this has nothing to do with templating systems.
>
That's good to know. Actually, it's more that good: I am looking into
Django again.
>> Can you provide a code example of printing the variable "torvalds" in
>> the GET request?
>> http://example.com/page.py?torvalds=tux
>> Should return this:
>> <html><body><p>tux</p></body></html>
>>
>> And something similar for a POST request?
>
>
> Using which framework ? If it's about Turbogears, I don't use it so I can't
> answer. If it's using Pylons, you can use almost whatever templating system
> you want - or not use any. If it's with Django, do you want it with or
> without the templating system ?
>
I'd love to see the non-templating Pylons example, and/or the Django
example. Better yet, a link to example code or the appropriate chapter
of TFM would be welcome. So far as I can tell, the fine manual does
not cover non-template output.
>> I hate to ask for code, but this conversation would be easier that way.
>
> Mmmm.... May I suggest that you first read the relevant documentation for
> the aforementionned frameworks ?
>
Yes, please! Where in the Django docs is the relevant chapter?
> Ok, here's a Django example without a template:
>
> # views.py
> def index(request):
> torvalds = request.GET.get("torvalds", "No torvalds here")
> return HttpResponse("<html><body>%s</body></html>" % torvalds)
>
>
Allright, but what if I need to output in the middle of the page? Say,
one row of a table that is neither the end nor beginning of the code?
I ask because the construct "return" makes me believe that this is not
good for this purpose.
> and here's an exemple using a template:
>
> # templates/index.html
>
> <html>
> <body>
> {{ torvalds }}
> </body>
> </html
>
>
> # views.py
> def index(request):
> torvalds = request.GET.get("torvalds", "No torvalds here")
> return render_to_response("index.html", dict(torvalds=torvalds))
>
Again, how could I output something in the middle of the page with the
templates?
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
More information about the Python-list
mailing list