Home > Net >  Flask Debugger Mode: Setting up Variables
Flask Debugger Mode: Setting up Variables

Time:07-12

I'm learning Flask and I want to create a small-scale application using this framework. However, the debug mode doesn't allow me to view changed content upon reload. Reloading the webpage doesn't help (I have to turn the server off and on every time I want to see changes). Any help would be appreciated.

Thank you

i) app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Change</p>"

ii) cmd prompt

set FLASK_APP=app.py
set FLASK_ENV=development
set FLASK_DEBUG=1

CodePudding user response:

Try using export instead of set i.e

export FLASK_APP=app.py
export FLASK_ENV=development
export FLASK_DEBUG=1

CodePudding user response:

For windows, try using a .env file i.e: Create a file called .env in your project folder, then add the values i.e

FLASK_APP=app.py
FLASK_ENV=development
FLASK_DEBUG=1

Then modify your code to look like this:

from flask import Flask
from dotenv import load_dotenv

load_dotenv()

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Change</p>"

Then install the dotenv module:

pip install python-dotenv

Then run your application.

  • Related