Env. Variables not set while running Minimal Flask application

前端 未结 19 1992

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

相关标签:
19条回答
  • 2021-01-30 03:47
    1. export FLASK_APP=run.py
    2. flask run --host=0.0.0.0

    then can run normally, output something like:

     * Serving Flask app "hello"
     * Forcing debug mode on
     * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger pin code: 353-795-063
    
    0 讨论(0)
  • 2021-01-30 03:48

    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"

    0 讨论(0)
  • 2021-01-30 03:48

    Your code is correct. Try setting the Command-Line variable like this :

    setx FLASK_APP run.py
    

    And then run it : flask run.

    0 讨论(0)
  • 2021-01-30 03:50

    You have to set the FLASK_APP variable outside of the virtual environment. I'm assuming the reason that it worked after @Fang restarted the command window is because that action automatically exited the virtual environment.

    So, if you're in the virtual environment (indicated by a (venv) at the start of line on command window), then type the following commands:

    deactivate
    
    set FLASK_APP=run.py
    
    venv\scripts\activate
    
    flask run
    
    0 讨论(0)
  • 2021-01-30 03:50

    Success with setx FLASK_APP test.py . Note: if not run, close command line and start other one.

    D:\projects\flask-oauthlibpy2>.evn\Scripts\activate
    
    (.evn) D:\projects\flask-oauthlibpy2>setx FLASK_APP test.py
    
    SUCCESS: Specified value was saved.
    
    (.evn) D:\projects\flask-oauthlibpy2>flask run
     * Serving Flask app "flask-oauthlibpy2.test"
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
    127.0.0.1 - - [24/May/2017 14:35:06] "GET / HTTP/1.1" 200 -
    
    0 讨论(0)
  • 2021-01-30 03:51

    Here is what worked for me:

    • Step 1: Open your CMD Command prompt
    • Step 2: Go on the same directory in which my python file was on.
    • Step 3: in the CMD command prompt run the command setx FLASK_APP sqlAlchemy.py
    • Step 4: close terminal
    • Step 5: In the CMD command prompt run the command python - m flask run

    I have an Alienware laptop and am using Windows 10.

    Not sure it worked but it was a combination of trial and ever. Depending on the OS you have the solution will vary it seems. IT could be an environmental variable issue but again not sure.

    - Here are other possible solutions that didn't work for me but I gathered them up as possibilities.

    • OPTION 2
    • set FLASK_APP=sqlalchemy.py
      • flask run
    • OPTION 3
    • set FLASK_APP=app
    • set FLASK_ENV=development
      • flask run Hope this helps.
    0 讨论(0)
提交回复
热议问题