摘要::如果我在视图函数中调用flash
,则get_flashed_messages(with_categories=True)
将返回一个元组列表,如预期的那样。但是,如果我在重定向之前致电flash
,则会获得dict
的列表!
我有一个相当复杂的应用程序,具有多个蓝图,请求和URL预处理和后处理,因此我无法找到一个最小的工作示例来演示我的问题(如果可以的话,我可能会有一个解...)。但是在我的主应用程序中,我有两条路线:
@app.route('/')
def index():
flash('this is the index', 'message')
return render_template("index.html")
@app.route('/testflash')
def testflash():
flash('testing flash', 'debug')
return redirect(url_for('index'))
在我的index.html
中,我有一个打印消息的块:
<div id="messages" class="clearfix" >
{% for cat,msg in get_flashed_messages(with_categories=true) %}
<div class="alert alert-{{ cat | replace('error','danger') }} alert-dismissable" >
{{ msg }} <a href="#" class="close" data-dismiss="alert" >×</a>
</div>
{% endfor %}
</div>
从这两次闪烁中,我得到:
{' t': ['debug', 'testing flash']}
('message', 'this is the index')
如果我制作一个仅包含那些视图的裸应用程序,它将按预期运行。因此,以某种方式在我的视图函数收到它之前,闪存队列已损坏。我的代码均未明确触摸session
。我可以肯定地说,所有蓝图的前/后处理仅适用于该蓝图的端点,这似乎可以通过在这些函数中放置一堆调试打印语句而看不到它们来得到确认。
那么我在哪里寻找发生这种情况的地方?除了设置secret_key
外,我没有为会话配置任何东西,因此它应该使用基于cookie的会话。
是否为最奇怪的错误颁奖?