为什么WSGI配置文件找不到我的Python变量?

时间:2017-09-20 15:02:49

标签: python python-3.x wsgi pythonanywhere

我正在尝试使用简单的Python应用程序设置PythonAnywhere,但WSGI配置似乎无法正确导入,我做错了什么?

#!/usr/bin/python3.6

import web
import urllib
from xml.dom import minidom

... [code] ...

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
    #app.wsgifunc()

我的WSGI如下

#!/usr/bin/python3.6

import sys

path = "/home/myUsername"
if path not in sys.path:
    sys.path.append(path)

from myPythonFileNameInSameDir import app as application
application.wsgifunc()

1 个答案:

答案 0 :(得分:2)

PythonAnywhere dev在这里 - 当您从WSGI文件导入web.py应用程序时,它不会在if __name__ == "__main__":部分中运行任何内容。

您需要在应用中执行此操作:

#!/usr/bin/python3.6

import web
import urllib
from xml.dom import minidom

... [code] ...

app = web.application(urls, globals())

if __name__ == "__main__":
    app.run()

...这在WSGI文件中:

#!/usr/bin/python3.6

import sys

path = "/home/myUsername"
if path not in sys.path:
    sys.path.append(path)

from myPythonFileNameInSameDir import app
application = app.wsgifunc()