Env. Variables not set while running Minimal Flask application

前端 未结 19 1993

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 04:01

    I had got the same issue while running the first hello world for flask.

    Ideally there should not be any space between so use set FLASK_APP=run.py

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

    Different shell programs have different ways to set the environment variable in it. So that Flask can discover you application correctly.

    • Unix Bash/Zsh (Linux, Mac, etc.):

      $ export FLASK_APP=hello
      $ flask run
      
    • Windows CMD:

      > set FLASK_APP=hello
      > flask run
      
    • Windows PowerShell:

      > $env:FLASK_APP = "hello"
      > flask run
      

    You can find more infomation in the Flask docs.

    0 讨论(0)
  • 2021-01-30 04:03
        > set FLASK_APP=Your_file_name.py
        > set FLASK_ENV=development
        > flask run
    

    it must be work for windows user only

    0 讨论(0)
  • 2021-01-30 04:07

    I had the same issue on windows and found a solution from the flask documentation: https://flask.palletsprojects.com/en/1.1.x/tutorial/factory/

    My file structure: Flask_folder>>app

    (NB! app folder contains: __init_.py and routes.py)

    > set FLASK_APP=app

    > set FLASK_ENV=development

    > flask run

    0 讨论(0)
  • 2021-01-30 04:12

    I fixed the same problem by closing the command window and restart it.

    0 讨论(0)
  • 2021-01-30 04:13

    Did you run your terminal as administrator? I had the same problem, and running cmd/PowerShell as admin fixed it for me.

    Edit: I spoke too soon. Running as admin did nothing.

    The real answer (to my problem, at least) is a combination of some of the other answers.

    1. Instead of using set FLASK_APP = myApp.py, use setx FLASK_APP myApp.py
    2. Restart the terminal, and FLASK_APP will have the new value
    0 讨论(0)
提交回复
热议问题