调试器是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引入了a bug;除非您明确传入-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的处理同样存在缺陷.