I've got a problem which is probably an embarrassing config issue.
Using lighttpd with flup and cheetah I'm getting an error when loading
templates.
FastCGI-stderr: Traceback (most recent call last):
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/flup/server/fcgi_base.py",
line 560, in run
protocolStatus, appStatus = self.server.handler(self)
File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/flup/server/fcgi_base.py",
line 1098, in handler
result = self.application(environ, start_response)
File "/Users/cesther/Documents/sites/release/web.py", line 1070, in
__call__
return self.func(e, o)
File "/Users/cesther/Documents/sites/release/web.py", line 894, in
wsgifunc
func()
File "/Users/cesther/Documents/sites/release/web.py", line 884, in
<lambda>
func = lambda: handle(getattr(mod, name), mod)
File "/Users/cesther/Documents/sites/release/web.py", line 378, in
handle
return tocall(*[urllib.unquote(x) for x in args])
File "/Users/cesther/Documents/sites/release/code.py", line 10, in
GET
web.render('view.html')
File "/Users/cesther/Documents/sites/release/web.py", line 829, in
render
t = _compiletemplate(template, base=base, isString=isString)
File "/Users/cesther/Documents/sites/release/web.py", line 781, in
__compiletemplate
else: text = open('templates/'+template).read()
IOError: [Errno 2] No such file or directory: 'templates/view.html'
Running the same code using "python code.py" works.
Running the simple 'hello world' example through lighttpd works, even a
take on the database example works (just printing the todo object).
As it seems the document root is getting lost somewhere here's the
lighttpd config:
server.modules = ("mod_fastcgi", "mod_rewrite")
server.document-root = "/Users/cesther/Documents/sites/release/"
fastcgi.server = ( "/code.py" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/Users/cesther/Documents/sites/release/code.py",
"max-procs" => 1
))
)
url.rewrite-once = (
"^/favicon.ico$" => "/static/favicon.ico",
"^/static/(.*)$" => "/static/$1",
"^/(.*)$" => "/code.py/$1",
)
Any ideas?
Thanks
File "/Users/cesther/Documents/sites/release/web.py", line 781,
in __compiletemplate
else: text = open('templates/'+template).read()
IOError: [Errno 2] No such file or directory:
'templates/view.html'
I've posted a problem that suspiciously looks the same, but I'm using
Apache & mod_python. Any idea how to solve this. Is it a config problem
or a code problem? Could it be in httpd.conf setup with the path to
the templates?
What do you mean by '... start lighttpd from the directory with
templates/ in it or
else chdir to that directory. ...'?
post description:
Cheetah templates failing (apache2,mod_python,py2.4.1)
http://groups.google.com/group/webpy/browse_thread/thread/d8c9f2adb704f951
You need to explicitly set/change the current working dir of the python
process to that of the document root.
Starting lighttpd in the directory above templates didn't work for me.
I checked this by commenting out the template related code and doing a
"print os.getcwd()" and got /
Therefore the other approach is to change dir into the document root.
Which I did using:
os.chdir('//Users//cesther//Documents//sites//release')
Yes, was set at root.
> Therefore the other approach is to change dir into the document root.
> Which I did using:
> os.chdir('//Users//cesther//Documents//sites//release')
Chose this approach.
Used os.chdir to change to document root.
Did not work.
I changed the code & templates to the root dir (instead of py below
root) to reduce chance of error.
ie: http://localhost/codep.py/
Below is the steps taken, error_log & code changes.
ps: the detail is included for others to follow later on.
------ steps ------
*using apache2, mod_python2, web.py 0.12, python 2.4.1
*found root dir of documents
-/var/www/html
*created template dir from root
-mkdir templates/
-cd templates/
-pwd /var/www/html/templates
*added view.html to templates dir
*added os.getcwd() & os.chdir to codep.py
*checked codep.py, web.py in root
*enter url into browser, http://localhost/codep.py/
*check error_log
-tail -f /var/log/httpd/error_log
------ steps ------
Heres what I found. Note 'templates/templates/view.html'
How I despise hard coded paths!
------ read error_log ------
*File "/var/www/html/web.py", line 785, in do_include\n
*text = open('templates/'+match.groups()[0]).read()\n
*IOError: [Errno 2] No such file or directory:
'templates/templates/view.html'\n
------ read error_log ------
------ codep.py ------
1 import web
2 DOC_ROOT = '//var//www//html'
3 urls = ('/(.*)', 'View')
4 class View:
5 def GET(self, name):
6 os.chdir(DOC_ROOT)
7 web.header('Content-Type','text/html; charset=utf-8')
8 try:
9 web.render('view.html')
10 except:
11 print 'Error: Template problem. '
12 print 'Python process dir = "%s"' % (os.getcwd())
13 #web.render('view.html')
15 main = web.wsgifunc(web.webpyfunc(urls))
15 if __name__ == "__main__": web.run(urls)
------ codep.py ------
I added a try/except to catch the error. Found the error in the log by
uncommenting L13.
and in context here
http://groups.google.com/group/webpy/browse_thread/thread/d8c9f2adb704f951