Unable to enable debug mode in Flask

I have a pretty basic Flask application, but for some reason Debug mode is not turned on, so whenever I get an error, I get 500 pages instead of a good debug page with tracing and all that. Here is my application / init .py:

from flask import Flask
from config import config


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api/v1.0')

    return app

and here is my config.py:

import os

basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
    SECRET_KEY = '12345'
    SQL_DRIVER = 'SQL Server Native Client 11.0'
    SQL_SERVER = 'WIN8\MSSQL2K12'
    SQL_DATABASE = 'LogMe'
    SQL_USER = 'LogMe'
    SQL_PASSWORD = 'password'

    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    DEBUG = True

config = {
    'development' : DevelopmentConfig
}

I sent the whole project to GitHub if there is a problem elsewhere, but I assume it is somewhere in these two files: https://github.com/jcaine04/perf-dash/tree/master/app

+4
source share
1 answer

WSGI; app.run(). WSGI, :

def create_app(config_name):
    app = Flask(__name__)

    # ...

    if app.debug:
        from werkzeug.debug import DebuggedApplication
        app.wsgi_app = DebuggedApplication(app.wsgi_app, True)

    return app

Flask-Script, runserver Flask WSGI .

, Flask- Script 2.0.3 ; , -d. , use_debugger true; , argparse store_true False, .

- -d flask_script/commands.py, --debug --no-debug self.use_debugger :

if self.use_debugger:
    options += (Option('-d', '--debug',
                       action='store_true',
                       dest='use_debugger',
                       help="(no-op for compatibility)",
                       default=self.use_debugger),)
    options += (Option('-D', '--no-debug',
                       action='store_false',
                       dest='use_debugger',
                       default=self.use_debugger),)

else:
    options += (Option('-d', '--debug',
                       action='store_true',
                       dest='use_debugger',
                       default=self.use_debugger),)
    options += (Option('-D', '--no-debug',
                       action='store_false',
                       dest='use_debugger',
                       help="(no-op for compatibility)",
                       default=self.use_debugger),)

default=self.use_debugger , .

self.use_reloader .

0.6.7 1.0 ; a 2.0.4 ( ).

+4

Source: https://habr.com/ru/post/1539816/


All Articles