使用bottle_flash2实现Bottle flash消息时报错AttributeError问题咨询
bottle_flash2 调用flash方法时报错
AttributeError: 'str' object has no attribute 'append' 因无法安装bottle_flash组件,当前使用bottle_flash2作为替代。代码完全参照该项目PyPI页面的示例编写,除了在routes.py中新增了程序启动的主函数外,其余内容与示例完全一致,但运行时一直报错AttributeError: 'str' object has no attribute 'append',未检索到同类问题的公开讨论,不清楚解决方向。
测试代码
routes.py
from bottle import Bottle, post, jinja2_template as template,run from bottle_flash2 import FlashPlugin # Flash Setup app = Bottle() COOKIE_SECRET = 'super_secret_string' app.install(FlashPlugin(secret=COOKIE_SECRET)) @app.route('/flash_sample_done') def flash_sample(): app.flash("flash message is here") # flash mesage is stored in list # Therefore, it is possible to store a multiple messages. app.flash("flash message 1") app.flash("flash message 2") return template('index.html', app = app) if __name__ == "__main__": run(app, host='localhost', port=8080, debug=True)
index.html
% messages = app.get_flashed_messages() % if messages: <div id=flash_messages> <ul> % for m in messages <li>{{ m[0] }}</li> % endfor </ul> </div> % endif
完整报错追踪栈
Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\bottle.py", line 868, in _handle return route.call(**args) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\bottle.py", line 1748, in wrapper rv = callback(*a, **ka) File "C:\Users\user\Desktop\temp\test\routes.py", line 11, in flash_sample app.flash("flash message is here") File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\bottle_flash2.py", line 32, in flash response.flash_messages.append((message, level)) AttributeError: 'str' object has no attribute 'append'
内容的提问来源于stack exchange,提问作者SadSalad
相关产品推荐
相关产品推荐

