Flask, python CONFIG.py not working

Hello Everybody,

I’m trying to put together Flask/python Config.py file and I’m not sure if its working or not. As you can see in the config.py ProdConfig class the debug is set to DEBUG=False. from the init.py its scripted as: app.config.from_object(‘config.ProdConfig’). But, in the terminal, it states “Debugger is active!”. is this mean the config file isn’t working or am I missing something?
No error message received.

What am i doing wrong?

config.py

from os import environ, path
from dotenv import load_dotenv

basedir = path.abspath(path.dirname(__file__))
load_dotenv(path.join(basedir, '.env'))

class Config:    
    #DEBUG=False
    TESTING=False       

class DevConfig(Config):      
    DEBUG = True    
    
class ProdConfig(Config):    
    TESTING = False
    DEBUG = False

init.py

import os
from flask import Flask, redirect, url_for
# from flask_sqlalchemy import SQLAlchemy
from config import Config

def create_app(app_config=None):
    app = Flask(__name__, instance_relative_config=True)    
    app.config.from_object('config.ProdConfig')

return app

Results from the terminal

venv) PS D:\xampp\htdocs\flaskLearning> flask run
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
 * Serving Flask app 'learning'
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit
 * Restarting with stat
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
 * Debugger is active!      
 * Debugger PIN: 366-622-259
1 Like

Why are you using dotenv here in addition to the config setup offered by flask? I wouldn’t bother with dotenv and just use flask’s config setup.

A second point is that Flask documentation states…

While it is possible to set DEBUG in your config or code, this is strongly discouraged. It can’t be read early by the flask command, and some systems or extensions may have already configured themselves based on a previous value.

They actually recommend making the FLASK_DEBUG option an environment variable or a variable passed in at the running of the command.

The DEBUG config value is special because it may behave inconsistently if changed after the app has begun setting up. In order to set debug mode reliably, use the --debug option on the flask command. flask run will use the interactive debugger and reloader by default in debug mode.

I often run projects like this through PyCharm and set the debug value as an environment variable as part of my configuration. You can also pass debug=True to the app.run() command to turn on the debugger.

1 Like

Hi Martyr2,
Thanks for the reply back. I took you advise and change a few code. For all intensive purpose the script is working. I feel that I’m missing something but for now I’m going to leave it the way it is as I already spent too much time on the config file :slight_smile:
Thanks again for the help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.