简体   繁体   English

apache2 mod_wsgi bottlepy NameError:名称“ os”未定义

[英]apache2 mod_wsgi bottlepy NameError: name 'os' is not defined

I am trying to use apache2 mod_wsgi to deploy bottle.py web application. 我正在尝试使用apache2 mod_wsgi来部署bottle.py Web应用程序。

I followed the instruction below: 我遵循以下指示:

http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi

Added a file /var/www/yourapp/app.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()

I added a file yourapp.py into /var/www/yourapp/: 我在/ 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)

Am I doing the right thing? 我做对了吗?

I get a Http 500 error, and found some error inside the log: 我收到Http 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

You need import os as the first line in your first file (app.wsgi). 您需要import os作为第一个文件(app.wsgi)的第一行。 You're trying to use the os module without having first imported it. 您正在尝试使用os模块,而无需先导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM