Cheetah templates failing (apache2,mod_python,py2.4.1)

18 views
Skip to first unread message

peter

unread,
Jan 19, 2006, 1:32:32 AM1/19/06
to web.py
I've got web.py going with apache2, python2.4.1 & mod_python2. I'm
currently attempting to get Cheetah templates working. Im trying to
get the simplist template example working (as per web.py/tutorial).

What I've done:
*downloaded & installed Cheetah 1.0
*modified codep.py to include
-web.render('view.html')
*created 'template' sub directory
*created 'view.html'
-used code in template example http://webpy.org/tutorial
-saved file to template directory as 'view.html'
*passed in url to browser
-'http://localhost/py/codep.py/'

What I get:
*error reported in web.py, L781
-File "/usr/lib/python2.4/site-packages/web.py", line 781, in
__compiletemplate\n
*the template file cannot be found.
-it exists on the file system.
*template directory is correctly named.
-checking the source (L781,784), template dir is hard coded to
'templates'

View logs & code
*view the error reported to my apache logs here
http://www.flickr.com/photos/bootload/88472790/
*view the code I used & code where web.py fails here
http://www.flickr.com/photos/bootload/88472791/


Can anyone suggest what I've missed?


Regs PR

deepak sarda

unread,
Jan 19, 2006, 4:59:24 AM1/19/06
to web.py
Hi Peter,

Does it help if you put web.py in the same folder as codep.py ?

-
deepak

peter

unread,
Jan 19, 2006, 5:19:21 AM1/19/06
to web.py
Hi deepak,

No.
---- did the following -----
*copy web.py to same dir
*rename web.py in */site-packages
*check /etc/httpd/conf/httpd.conf
-nothing there
*check /etc/httpd/modules.d/16_mod_python.conf
-nothing to note there
<Directory /var/www/html>
<IfModule mod_mime.c>
AddHandler python-program .spam
</IfModule>
AddHandler python-program .py
PythonHandler wsgiref.modpython_gateway::handler
PythonOption application codep::main
PythonDebug On
</Directory>
*restart apache
*check logs
-reports 500 in access_log
-reports IOError:
[Errno 20] Not a directory: 'templates/view.html'\n'
------

But what was interesting was a post I read 'problem :: lighttpd, flup,
cheetah'. You can find it here:
http://groups.google.com/group/webpy/browse_thread/thread/3f330d94c1e8c82d

Check Aarons response to Chris's problem. He mentions ...

'You have to start lighttpd from the directory with templates/ in
it or
else chdir to that directory. '

The error looks the same. But I have no idea how to make sense of the
suggestion wrt Apache. (if this is the problem).

Hope its not an Apache path/permissions problem.

peter

unread,
Jan 19, 2006, 7:31:34 PM1/19/06
to web.py
discussion also here, 'problem :: lighttpd, flup, cheetah'
http://groups.google.com/group/webpy/browse_thread/thread/3f330d94c1e8c82d/ff5c649338fff1f2?

suggestion to
*'explicitly set/change the current working dir of the python process
to that of the document root. '
*check by commenting out the template related code and doing a "print
os.getcwd()"
*change dir into the document root. ...
os.chdir('//Users//cesther//Documents//sites//release')

Result fails.

peter

unread,
Jan 20, 2006, 5:48:35 AM1/20/06
to web.py
Solved

Thanks for the suggestions Chris & Depak.

Took a bit of fiddling around, poking into the code but I have a
workable solution. Firstly it avoids setting the document root.
The hint to the solution was looking closely at the web.render
argument sig and realising you can pass in the template.

This of course assumes the web.render sig is not altered. Please
check before you try web.py (version 0.123)

I've added the shots/comments on flickr at
code: http://www.flickr.com/photos/bootload/88879847/
logs: http://www.flickr.com/photos/bootload/88879846/
working: http://www.flickr.com/photos/bootload/88879844/

Hopefully if others using the apache route can learn something from the
notes.

Regs PR

------ steps taken ------
*read web.render sig
-around L 817
*understand 'def render' sig & arguments passed
-def render(template, terms=None, asTemplate=False, base=None,
isString=False):
-if you first read the template file, pass in the contents as template
and set the isString to true you can pass in a template from any
directory
path with any title
*read the template file using standard python file syntax &
pass to web.render function.
-build file path
-open file
-read file into a variable
-close file
-set web.render arguments
*test & view logs.
------ steps taken ------


------ comments ------
*5 points for GPL so I can read/modify the source
*for web.render
-allowence for template to be passed in, 1 point
*for web.__compiletemplate some work needs to be done
-why hard code template paths?, L 781, -1 point
-why read the same files twice?, L784, -1 point
*minimal error checking
-no unit tests (compare to Cheetah), -1 point
------ comments ------


------ codep.py ------
1 #!/usr/bin/env python
2 import os
3 import web
4
5 DOC_ROOT = '/var/www/html'
6 DOC_TPL = 'templates'
7 FILE_TPL = 'view.html'
8 urls = ('/(.*)', 'View')
9
10 class View:
11 def GET(self, name):
12 # set mime for browser
13 web.header('Content-Type','text/html; charset=utf-8')
14 t = None
15 fp = None
16
17 # graceful landing if the file or template render fails
18 try:
19 # given filepath, read the template file
20 fp = "%s/%s/%s" % (DOC_ROOT, DOC_TPL, FILE_TPL)
21 f = open(fp,'r')
22 t = f.read()
23 f.close()
24
25 #------
26 # render: look at method sig for web.render. Notice
isString flag & template
27 # if you set isString to True & pass in template
it will work.
28 #
29 # render(template, terms=None, asTemplate=False,
base=None, isString=False)
30 #------
31 web.render(t, None, False, None, True)
32 except:
33 print "Error: Template problem.<br>"
34 print "Filepath = '%s'<br>" % (fp)
35 print "Template = '%s'<br>" % (t)
36 print "Root = '%s'<br>" % (os.getcwd())
37 #web.debugerror() # nice default debug information
38
39 main = web.wsgifunc(web.webpyfunc(urls))
40 if __name__ == "__main__":
41 web.run(urls)
------ codep.py ------

Reply all
Reply to author
Forward
0 new messages