Web development with Python 3.1

Dotan Cohen dotancohen at gmail.com
Wed Oct 28 09:39:03 EDT 2009


>> I insist on handling the HTML myself.
>
> I just don't get how embedding HTML in applicative code - a well-known
> antipattern FWIW - relates to "handling the HTML yourself". Can you *please*
> explain how a templating system prevents you from "handling the HTML"
> yourself.
>

>From the little that I played with Django, it looked like I would (for
the sake of argument I am just using the term output, but the
intention should be clear) output "Hello, world!" and Django would
mangle that into <html><body><p>Hello, world!</p></body></html>. It
did not look like I had any control over the tags at all.


>>> And
>>> even if not, what you will do is ... code your own webframework.
>>
>> That is why I am looking for a class that handles the backend stuff,
>> but lets _me_ handle the HTML.
>
> For God's sake : *why on earth do you believe that using a templating system
> will make you loose _any_ control on the HTML code ???*
>

Because that's what I've seen of them.


>>> And at least pylons/TG2 lets you return whatever you want instead, as a
>>> string. Not via "print" though - which is simply only for CGI, and no
>>> other
>>> means (e.g. mod_wsgi) of python-web-programming.
>>>
>>
>> I am trying to follow you here. What is "return whatever you want"?
>> Return HTML to stdout to be sent to the browser?
>
> please leave stdout out of here - it's HTTP, so what we have are HTTP
> requests and HTTP responses - not stdin nor stdout. Using these streams as a
> mean of communication between the web server and the applicative code is
> just plain old low-level GCI stuff. Your application code shouldn't have any
> knowledge of this implementation detail - it should receive (a suitable
> representation of) an HTTP request, and generate (a suitable representation
> of) an HTTP response.

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?

I hate to ask for code, but this conversation would be easier that way. Thanks.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il



More information about the Python-list mailing list