先安装pip install flask_debugtoolbar
然后在注册文件中【这里不太理解为啥是在注册文件中写】:
from controllers.index import index_page
from application import app
from flask_debugtoolbar import DebugToolbarExtension
toolbar = DebugToolbarExtension(app)
app.register_blueprint(index_page,url_prefix='/learning')
但是报了如下的错
H:\new_to_flask>python run.py runserver
Traceback (most recent call last):
File "run.py", line 3, in <module>
from register import *
File "H:\new_to_flask\register.py", line 7, in <module>
toolbar = DebugToolbarExtension(app)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask_debugtoolbar\__init__.py", line 58, in __init__
self.init_app(app)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask_debugtoolbar\__init__.py", line 69, in init_app
"The Flask-DebugToolbar requires the 'SECRET_KEY' config "
RuntimeError: The Flask-DebugToolbar requires the 'SECRET_KEY' config var to be set
于是,在配置文件中,把SECRET_KEY设置一下,这里设置123456
但是,我这里没能显示toolbar。有了一些警告信息:
C:\ProgramData\Anaconda3\lib\site-packages\flask_debugtoolbar\__init__.py:213: UserWarning: Could not insert debug toolbar. </body> tag not found in response.
warnings.warn('Could not insert debug toolbar.'
正常情况下,应该是这样的: