Reputation: 321
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:
"set FLASK_ENV=development"
on my terminal from this stackoverflow solution I am on Windows, so I instead used setpython-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 mentionedif __name__ == '__main__':
app.run(debug=True)
python-dotenv
here and added load_dotenv()
after my import statementsSee 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
Upvotes: 0
Views: 3583
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
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