Thread: [PythonWeb.org] Problems using web.template.
Status: Beta
Brought to you by:
thejimmyg
|
From: Wayne P. <sha...@gm...> - 2005-06-23 19:15:18
|
I just found PythonWeb and have started working through the examples.=20
Unfortunately I can't get a simple template working properly, parts of
the HTML disappear or are printed out of order in the final output.
I have the following files:
(webtest.py)
#!/usr/bin/python
import web.template
dict =3D {
=09'welcomeMessage': 'Welcome to the test page.',
=09'testVar': True,
=09'title': 'Example'
}
print web.template.parse(
=09type=3D'xyaptu',
=09file=3D'web-template.tmpl',
=09dict=3Ddict
)
(web-template.tmpl)
<html>
=09<head>
=09=09<title>$title</title>
=09</head>
=09
=09<body>
=09=09<p>$welcomeMessage</p>
=09=09=09<py-open code=3D"if testVar:" />
=09=09=09=09The variable is: True
=09=09=09<py-clause code=3D"else:" />
=09=09=09=09The variable is: False
=09=09=09<py-close/>
=09</body>
</html>
When I run 'python webtest.py' from the command line (Fedora 3) I get
the following:
<html> <head> <title>Example</title>
<body>> <p>Welcome to the test page.</p>
=20
The variable is: True
</html> </body>
Two things happen, </head> disappears and the last two items are
flipped. Running webtest.py through Apache gives me an Internal
Server Error due to malformed headers.
Does anyone have suggestions on what could be causing this? I am
using Python 2.3.4 with the latest version of PythonWeb.
Thanks for any help,
Wayne
|
|
From: James G. <ja...@py...> - 2005-06-23 20:57:30
|
Hi Wayne, I've tested your code on both Python 2.2 and Python 2.4 and it works as it should for me, I couldn't reproduce your error I'm afraid. Cheetah is the most powerful and best supported templating engine that the web modules support so I'd recommend using that instead. The example is at http://www.pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib/example-file-web-template-cheetah.html As for the Internal Server Error on Apache, that is usually caused because you have forgotten to print the HTTP header before the main content. Add the line: print "Content-type: text/html\n\n" after the import web.template line and you should avoid the error. Hope that is of some use! James Wayne Pierce wrote: >I just found PythonWeb and have started working through the examples. >Unfortunately I can't get a simple template working properly, parts of >the HTML disappear or are printed out of order in the final output. > >I have the following files: > >(webtest.py) > >#!/usr/bin/python > >import web.template > >dict = { > 'welcomeMessage': 'Welcome to the test page.', > 'testVar': True, > 'title': 'Example' >} > >print web.template.parse( > type='xyaptu', > file='web-template.tmpl', > dict=dict >) > >(web-template.tmpl) > ><html> > <head> > <title>$title</title> > </head> > > <body> > <p>$welcomeMessage</p> > <py-open code="if testVar:" /> > The variable is: True > <py-clause code="else:" /> > The variable is: False > <py-close/> > </body> ></html> > >When I run 'python webtest.py' from the command line (Fedora 3) I get >the following: > ><html> <head> <title>Example</title> > <body>> <p>Welcome to the test page.</p> > >The variable is: True ></html> </body> > > >Two things happen, </head> disappears and the last two items are >flipped. Running webtest.py through Apache gives me an Internal >Server Error due to malformed headers. > >Does anyone have suggestions on what could be causing this? I am >using Python 2.3.4 with the latest version of PythonWeb. > >Thanks for any help, > >Wayne > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click >_______________________________________________ >Lemon-webmodules mailing list >Lem...@li... >https://lists.sourceforge.net/lists/listinfo/lemon-webmodules > > |
|
From: Wayne P. <sha...@gm...> - 2005-06-24 00:22:06
|
James, Thanks for the response. I did figure out the problem...sorta. The code I used was from http://www.pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib/e= xample-file-web-template-xyaptu.html which dind't have the headers or a 'print web.header()'. Which is what was causing the Apache error. Oddly enough, when I put a blank line between the closing BODY and closing HTML tags everything works fine. I then removed the space and got the same error, but it went away when I put the blank line back in. I'm going to test the same code on a different system tomorrow to see if I can narrow it down. Wayne On 6/23/05, James Gardner <ja...@py...> wrote: > Hi Wayne, >=20 > I've tested your code on both Python 2.2 and Python 2.4 and it works as > it should for me, I couldn't reproduce your error I'm afraid. Cheetah is > the most powerful and best supported templating engine that the web > modules support so I'd recommend using that instead. The example is at > http://www.pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib= /example-file-web-template-cheetah.html >=20 > As for the Internal Server Error on Apache, that is usually caused > because you have forgotten to print the HTTP header before the main > content. Add the line: >=20 > print "Content-type: text/html\n\n" >=20 > after the import web.template line and you should avoid the error. >=20 > Hope that is of some use! >=20 > James >=20 > Wayne Pierce wrote: >=20 > >I just found PythonWeb and have started working through the examples. > >Unfortunately I can't get a simple template working properly, parts of > >the HTML disappear or are printed out of order in the final output. > > > >I have the following files: > > > >(webtest.py) > > > >#!/usr/bin/python > > > >import web.template > > > >dict =3D { > > 'welcomeMessage': 'Welcome to the test page.', > > 'testVar': True, > > 'title': 'Example' > >} > > > >print web.template.parse( > > type=3D'xyaptu', > > file=3D'web-template.tmpl', > > dict=3Ddict > >) > > > >(web-template.tmpl) > > > ><html> > > <head> > > <title>$title</title> > > </head> > > > > <body> > > <p>$welcomeMessage</p> > > <py-open code=3D"if testVar:" /> > > The variable is: True > > <py-clause code=3D"else:" /> > > The variable is: False > > <py-close/> > > </body> > ></html> > > > >When I run 'python webtest.py' from the command line (Fedora 3) I get > >the following: > > > ><html> <head> <title>Example</title> > > <body>> <p>Welcome to the test page.</p> > > > >The variable is: True > ></html> </body> > > > > > >Two things happen, </head> disappears and the last two items are > >flipped. Running webtest.py through Apache gives me an Internal > >Server Error due to malformed headers. > > > >Does anyone have suggestions on what could be causing this? I am > >using Python 2.3.4 with the latest version of PythonWeb. > > > >Thanks for any help, > > > >Wayne > > > > > >------------------------------------------------------- > >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >from IBM. Find simple to follow Roadmaps, straightforward articles, > >informative Webcasts and more! Get everything you need to get up to > >speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=3Dclick > >_______________________________________________ > >Lemon-webmodules mailing list > >Lem...@li... > >https://lists.sourceforge.net/lists/listinfo/lemon-webmodules > > > > >=20 > |