I am trying to follow the flask documentation on my windows machine given at the following link: http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode
Firstly I wrote the code below in a python script:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(debug=True)
I saved this in a file called run.py
Then wrote this command in the command window:
set FLASK_APP = run.py flask run
Upon running this, I am getting the following error:
"Error: Could not locate flask application. You did not provide the FLASK_APP environment variable"
I was expecting to get this instead:
Running on http://127.0.0.1:5000/
Can somebody tell me how to fix this?
Command-line: Similarly, the FLASK_ENV variable sets the environment on which we want our flask application to run. For example, if we put FLASK_ENV=development the environment will be switched to development. By default, the environment is set to development.
New in version 1.0. The environment in which the Flask app runs is set by the FLASK_ENV environment variable. If not set it defaults to production . The other recognized environment is development .
I faced the same issue while using PowerShell and that fix worked for me:
instead of using set FLASK_APP = run.py
, try $env:FLASK_APP = "run.py"
If you are using powershell it does not works i dont know why please use cmd.exe
since i use VScode editor it provide powershell as a terminal(ctrl + back-tick
) by default so i was trying to run flask app on the powershell and it was giving me same response as you are getting
open cmd.exe (or if you are VSCode user like me simply write cmd
on that terminal, or you can also press Ctrl + Shift + C
to open a windowed cmd terminal)
set FLASK_APP=hello.py
(without spaces, only for first run then it remember until restart of cmd)
flask run
(or just flask will also work)
note: this is only for windows user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With