0

trying to host my flask app (run.py) on PythonAnywhere. Have my virtualenv setup and all of my modules imported via pip. The flask app is stored at this location:

/home/goldsilvermonitor/GSM/run.py

Set up my WSGI file and it keeps giving my the error:

TypeError: 'module' object is not callable

My flask file look like this: (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)

And my WSGI file looks like this:

        # +++++++++++ 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.

I have no idea what is causing this error. Have tried reuploading the files, redoing the WSGI config. But to no avail. If someone could help me then that would be great! Also should I remove the debug=true from the flask file before I go live?

1 Answer 1

0

You're trying to import a module (the file run.py) and then use it as an application; the application is the app object in that file, so in the WSGI file you should replace this:

import run as application  # noqa

...with this:

from run import app as application  # noqa
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.