Issue
I'm new to Flask. To launch the flask app, I did python -m flask run
but I repeatedly get the error:
Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one.
I am using a virtualenv
on a Windows 10 machine
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
I expected a web server to start and to be able to navigate to localhost http://127.0.0.1:5000/
where I could view Hello, World!
on my browser, but that never happened.
Solution
Instead of just "flask" use FLASK_APP=theflaskapp.py
, like what Marco suggested:
env FLASK_APP=theflaskapp.py python -m flask run
This should fix it, if not, make sure you are executing the command to run the script in the same directory as it. You should also check if the problem is in flask or not by running "python theflaskapp.py" (In the same directory as the flask app still) and see if it works at all.
Answered By - user10997580
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.