Web development with Python 3.1
Dotan Cohen
dotancohen at gmail.com
Wed Oct 28 10:38:21 EDT 2009
> *Why* on earth do you think using a templating system will give you any less
> control on the generated HTML ?
>
Because I am wrong. I have already come to that conclusion.
I know that Python is far enough developed that if I feel that I am
fighting it, then _I_ am in the wrong, not Python. However, I still
need to see that Python can do what I need in a comfortable fashion.
>> And if I need to add a variable or three in there?
>
> - first solution : use string formatting
>
> python 2.x example:
>
> unmaintanable_html = """
> <html>
> <head>
> <title>%(title)s</title>
> </head>
> <body>
> <h1>%(h1)s</h1>
> <p>%(text)s</p>
> </body>
> </html>
> """
>
> data = dict(
> title="index",
> h1="Poor man's templating",
> text="Won't get you very far..."
> )
>
> return HttpResponse(unmaintanable_html % data)
>
That's fine for single variables, but if I need to output a table of
unknown rows? I assume that return means the end of the script.
Therefore I should shove the whole table into a variable and then copy
that variable to the array "data"?
> - second solution: do basically the same thing with a template system -
> which will give you much more power and options...
>
I will look further into the Django templates, I promise. But I would
still like to know how to work with Python proper.
>> Static HTML I can
>> do without Python.
>
> Sorry, I forgot to setup a database etc for this example !-)
>
I meant that I would like to see how to output variables, which you have shown.
Thanks. I am stubborn, but I am willing to learn.
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
More information about the Python-list
mailing list