如何在pythonanywhere.com上部署CherryPy

我有一个在Flask上开发的
python应用程序.一切正常离线,我也尝试在CherryPy上成功部署.现在,我正在尝试在www.pythonanywhere.com上部署它.

这是我用于在CherryPy上部署Flask应用程序的deploy.py

from cherrypy import wsgiserver
from appname import app

def initiate():
    app_list = wsgiserver.WSGIPathInfoDispatcher({'/appname': app})
    server = wsgiserver.CherryPyWSGIServer( ('http://username.pythonanywhere.com/'), app_list)
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()

print "Server initiated..."
initiate()
print "Ended"

我在pythonanywhere.com上创建了一个“手动配置”应用程序.
这是配置文件(username_pythonanywhere_com_wsgi.py):

import sys

path = '/home/username/appname'
if path not in sys.path:
    sys.path.append(path)

import deploy

deploy.initiate()

现在我很确定它“几乎可以工作”,因为在服务器日志中我可以看到我的“服务器启动…”消息.

2013-09-27 09:57:16 +0000 username.pythonanywhere.com - *** Operational MODE: single process ***
Server initiated...

现在问题是,当我尝试查看我的应用程序username.pyhtonanywhere.com/about时,它超时了.
我认为这是由于启动CherryPy服务器时提供的端口不正确(在deploy.py中).

谁能告诉我如何正确启动CherryPy服务器?

最佳答案 Joe Doherty是对的.在wsgi文件中你想要更像这样的东西:

import sys
sys.path = [ <path to your web app> ] + sys.path
from cherrypy._cpwsgi import CPWSGIApp
from cherrypy._cptree import Application

from <your_web_app> import <your web app class> 
config_path = '<path to your cherrypy config>'
application = CPWSGIApp(
    Application(<your web app class>(), '', config = config_path)

我在<> s中根据您的特定应用设置了所有内容.

点赞