2

I am trying to learn flask and for the same created a small program. When I try to run it I am getting the below error. flask run Error-

* Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

if I try to change the file name to app.py it runs smooth but when the file name is flaskblog.py it isn't working.

I tried setting up the environment variables as suggested in the blog-> How to set environment variables in PyCharm? but nothing worked.

Screenshots attached. content of environment variable file

shows envfile option is checked under flaskblog configuration

environment variable at project level

at python console level

os.environ['FLASK_APP'] output

Arpit Rathod
  • 91
  • 1
  • 4
  • 11
  • To add, if I run the code with `print(os.environ['FLASK_APP'])` this gives me correct output but the same doesn't work on the terminal – Arpit Rathod May 01 '20 at 18:43

2 Answers2

2

Open Settings -> Tools -> Terminal and there set up the environment variable FLASK_APP=app.py. Next, perform restart of PyCharm.

psota
  • 21
  • 2
1

I was able to resolve this by setting up the environment variable on the terminal itself. set FLASK_APP=flaskblog.py

and then it ran like smoothly.

Arpit Rathod
  • 91
  • 1
  • 4
  • 11