Duke3e33
Duke3e33

Reputation: 321

Flask environment not changing to development

Whenever running my Flask app on VSCode I am unable to change the environment to development. I have searched relevant links on this topic and tried all the solutions and combinations of solutions, nothing so far has worked. I would like my app to refresh whenever I make a change in either any of the template files or my app.py file. Here is a list of what I've tried:

  1. Typing in "set FLASK_ENV=development" on my terminal from this stackoverflow solution I am on Windows, so I instead used set
  2. Pip installing python-dotenv and creating a .env or .flaskenv. file inside my root directory (yes I tried both) then adding FLASK_ENV=development as well as set FLASK_ENV=development inside both files (at different times trying all combinations) like this stackoverflow solution mentioned
  3. Editing my main flask app file with the lines mentioned in the solution from list item number two...
if __name__ == '__main__':
app.run(debug=True)
  1. Yes I have read the documentation for python-dotenv here and added load_dotenv() after my import statements

See here start of my app.py code:

"""This is my controller"""

import re

from flask import Flask, render_template, request, redirect, session
from cs50 import SQL
from dotenv import load_dotenv

load_dotenv()


from flask_sqlalchemy import SQLAlchemy 

# turn the current file into a web application that will listen for browsers requests
# __name__ refers to the current file
app = Flask(__name__)

if __name__ == '__main__':
    app.run(debug=True)

And as you can see Environment: production still shows from terminal window

enter image description here

Upvotes: 0

Views: 3583

Answers (2)

flomaster
flomaster

Reputation: 1812

I discovered that for some reason Flask uses ENV variable instead of FLASK_ENV.

Try setting ENV=development in your .env file, it worked for me.

Upvotes: 0

Dauros
Dauros

Reputation: 10557

With powershell the syntax for env vars is different. To change the FLASK_ENV variable, type:

$env:FLASK_ENV = "development" 

You can verify it with gci env: command that list all of the env vars. After that the flask run will run in development mode.

Upvotes: 3

Related Questions