为什么 WSGI 配置文件找不到我的 Python 变量?
Why can't WSGI configuration file find my Python variable?
我正在尝试使用一个简单的 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()
PythonAnywhere dev here -- 当您从 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()
我正在尝试使用一个简单的 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()
PythonAnywhere dev here -- 当您从 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()