Web development with Python 3.1

Dotan Cohen dotancohen at gmail.com
Wed Oct 28 14:47:45 CET 2009

>> I insist on handling the HTML myself. As for converting the request
>> variables into Python variables, if a class/framework makes that
>> easier then I would gladly use it. My question was serious. How can I
>> do those things?
> Using a framework? In Pylons/TG2, my code looks like this:
> def some_form_action(self, name, email, password):
>   ....
> so HTTP-variables get parsed, validated, converted, and *then* passed to my
> actual code.

I know how to call a function, but how do I use the variables? How do
I respond (I am avoiding the term output) with the value of the GET
variable "torvalds", for example? And similarly for a POST variable?

>>> But then do you deal with headers correctly?
>> Yes, so far as I know. This is actually simpler than the HTML, just be
>> careful not to output two newline characters in sequence (thereby
>> ending the header).
> Oh my god. If two newlines are all you think that there is to properly
> writing HTTP-headers, no wonder *you* wonder what to use a webframework
> for.

I was being brief. I don't pretend to know the whole protocol by
heart, but I get by that far. :)

>>> Do you respect character
>>> encodings?
>> Yes! UTF-8 from database to scripting language to HTTP request.
> And if the browser sends them in different encoding? Frameworks make you
> deals with unicode only. Decoding/Encoding, setting the necessary

That's what I wrote below:

>>> Form-encodings?
>> Yes, UTF-8 the in the other direction. However, as form data can be
>> spoofed, I would like a function that checks it. Does Python have such
>> a function? What class does?
> Frameworks do check for HTTP-headers that contain the encoding, and thus
> convert incoming data to unicode.

That is useful, thanks.

>>> Is your generated HTML valid?
>> Naturally, even though this is not a Python issue.
> "Naturally" with print-statements?

"Carefully" with print statements.

>>> Do you parse
>>> content negotiation headers?
>> No. I hate sites that do that. If the page is available in another
>> language, their is a link in the corner.
> Again, you don't seem to really know much about webapps. Content-negotiation
> isn't about languages, it's about content-types. Such as serving HTML or
> JSON from the same URL. But let me guess, you hate applications that do
> that?

I used to serve WML-specific "decks" to known mobile UA's, but I've stopped.

> I don't have the *slightest* doubt about that. In fact, I'm pretty sure you
> can make pretty bad webapplications in pretty much everything you touch.
> Good luck with that.

I am a mechanical engineering student, not CS. I am doing this for my
own use and enjoyment. I don't need luck with that, I don't have any
customers. If someone were to come along asking me to code for them, I
would send them to you!

Dotan Cohen


More information about the Python-list mailing list