Web development with Python 3.1

Diez B. Roggisch deets at nospam.web.de
Wed Oct 28 05:16:52 EDT 2009


Dotan Cohen schrieb:
>> While I know that to be true in the general sense, from what I've
>> looked at Django and other frameworks it seems that the web frameworks
>> push the coder to use templates, not letting him near the HTML.
>>
>> For instance, I was looking for a class / framework that provided a
>> proven method of decoding cookies (setting them is no problem),
>> decoding POST and GET variables, escaping variables for safe entry
>> into MySQL, and other things. Django and the other frameworks seem to
>> force the user to use templates. I just want the functions, and to
>> print the HTML as stdout to the  browser making the request. I had to
>> settle on PHP to do this, which admittedly is what PHP was invented to
>> do. However, for obvious reasons, I would have prefered to code in
>> Python. In fact, I still would.
>>
> 
> I should probably expand on this:
> 
> How can I get an array with all the GET variables in Python?
> How can I get an array with all the POST variables in Python?
> How can I get an array with all the COOKIE variables in Python?
> How can I get the request URI path (everything after
> http://[www.?]example.com/)?
> 
> That's all I want: no templates and nothing between me and the HTML.
> The HTTP headers I can output to stdout myself as well.

Again: if you insist on doing everything yourself - then of course any 
library or framework isn't for you.


But then do you deal with headers correctly? Do you respect character 
encodings? Form-encodings? Is your generated HTML valid? Are 
timestamp-formats generated according to RFCs for your cookies? Do you 
parse content negotiation headers?

I think you underestimate the task it is to make a webapplication good. 
And even if not, what you will do is ... code your own webframework. 
Because there is a lot of boilerplate otherwis. If that's a 
learning-experience your after, fine.

Besides, yes, you can get all these things nonetheless. You just don't 
need them most of the time.

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.

Diez



More information about the Python-list mailing list