PythonAnywhere和Flask应用不断返回错误代码

问题描述 投票:0回答:1

试图在PythonAnywhere上托管我的Flask应用(run.py)。将我的virtualenv设置和我的所有模块都通过p​​ip导入。烧瓶应用程序存储在以下位置:

/home/goldsilvermonitor/GSM/run.py

设置我的WSGI文件,它不断给我错误:

TypeError: 'module' object is not callable

我的烧瓶文件如下所示:(run.py)

    from flask import Flask, flash, redirect, render_template, request, session, abort, url_for
app = Flask(__name__)

# ./Home Script:
@app.route("/")
@app.route("/index")
def index():
    return render_template('index.html')

# ./Disclaimer Page:
@app.route("/disclaimer")
def disclaimer():
    return render_template('disclaimer.html')

# ./data.xml:
app.route("/dataxml")
def dataxml():
    return render_template('data.xml')

# ./404 Page
@app.errorhandler(404)
def page_not_found(e):
    # 404 status set explicitly
    return render_template('404.html'), 404

# FLask Debug Script:s
if __name__ == "__main__":
    app.run(host="0.0.0.0", port='5000', debug=True)

我的WSGI文件看起来像这样:

        # +++++++++++ FLASK +++++++++++
# Flask works like any other WSGI-compatible framework, we just need
# to import the application.  Often Flask apps are called "app" so we
# may need to rename it during the import:
#
#
import sys
#
## The "/home/goldsilvermonitor" below specifies your home
## directory -- the rest should be the directory you uploaded your Flask
## code to underneath the home directory.  So if you just ran
## "git clone [email protected]/myusername/myproject.git"
## ...or uploaded files to the directory "myproject", then you should
## specify "/home/goldsilvermonitor/myproject"
path = '/home/goldsilvermonitor/GSM'
if path not in sys.path:
    sys.path.append(path)
#
import run as application  # noqa
#
# NB -- many Flask guides suggest you use a file called run.py; that's
# not necessary on PythonAnywhere.  And you should make sure your code
# does *not* invoke the flask development server with app.run(), as it
# will prevent your wsgi file from working.

我不知道是什么导致了此错误。尝试重新上传文件,重做WSGI配置。但无济于事。如果有人可以帮助我,那就太好了!我还应该在上线之前从烧瓶文件中删除debug = true吗?

python hosting wsgi pythonanywhere
1个回答
0
投票

您正在尝试导入模块(文件run.py),然后将其用作应用程序;该应用程序是该文件中的app对象,因此在WSGI文件中应替换为:

import run as application  # noqa

...与此:

from run import app as application  # noqa
© www.soinside.com 2019 - 2024. All rights reserved.