【问题标题】:apache2 mod_wsgi bottlepy NameError: name 'os' is not definedapache2 mod_wsgi bottlepy NameError: name 'os' is not defined
【发布时间】:2013-02-22 15:21:59
【问题描述】:

我正在尝试使用 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)

我做对了吗?

我收到一个 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

【问题讨论】:

    标签: python apache mod-wsgi bottle


    【解决方案1】:

    您需要 import os 作为您的第一个文件 (app.wsgi) 的第一行。您正在尝试使用 os 模块而不首先导入它。

    【讨论】:

    • 我得到了这个:对不起,请求的 URL 'localhost/hello' 导致错误:未找到:'/hello'
    • 那是因为你期待/hello/:name 并且只输入'/hello'
    猜你喜欢
    • 2021-02-16
    • 2017-12-09
    • 2022-12-02
    • 2013-04-09
    • 1970-01-01
    • 2020-11-07
    • 2017-01-09
    • 2017-06-14
    相关资源
    最近更新 更多