apache2 mod_wsgi bottlepy 未定义名称 'os' 的 NameError
我正在尝试使用apache2的mod_wsgi来部署一个用bottle.py写的网页应用。
我按照下面的说明进行了操作:
http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi
我在/var/www/yourapp/目录下添加了一个文件app.wsgi:
# Change working directory so relative paths (and template lookup) work again
os.chdir(os.path.dirname(__file__))
import bottle
# ... build or import your bottle application here ...
# Do NOT use bottle.run() with mod_wsgi
application = bottle.default_app()
我还在/var/www/yourapp/目录下添加了一个文件yourapp.py:
from bottle import route, run, template
@route('/hello/:name')
def index(name='World'):
return template('<b>Hello {{name}}</b>!', name=name)
我这样做对吗?
我遇到了一个500错误,并在日志里发现了一些错误信息:
[Fri Feb 22 15:03:38 2013] [error] [client 192.168.0.104] os.chdir(os.path.dirname(__file__))
[Fri Feb 22 15:03:38 2013] [error] [client 192.168.0.104] NameError: name 'os' is not defined
ke@dslds /var/log/apache2 $ NameError: name 'os' is not definedNameError: name 'os' is not defined
1 个回答
1
你需要在你的第一个文件(app.wsgi)的第一行加上 import os
。因为你想使用 os
这个模块,但还没有先把它引入进来。