在烧瓶中发布/重定向/获取模式

编程入门 行业动态 更新时间:2024-10-10 15:28:39
本文介绍了在烧瓶中发布/重定向/获取模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的玩具应用程序的查看功能是:

The view function of my toy app was:

@app.route('/', methods=['GET', 'POST']) def index(): name = None form = NameForm() if form.validate_on_submit(): name = form.name.data form.name.data = '' return render_template('index.html', form=form, name=name)

当我使用PRG时,它看起来像这样:

And it looks like this when I use PRG:

@app.route('/', methods=['GET', 'POST']) def index(): form = NameForm() if form.validate_on_submit(): session['name'] = form.name.data return redirect(url_for('index')) return render_template('index.html', form=form, name=session.get('name'))

如您所见,form.name.data = ''行用于在第一个版本中清除输入字段,但在第二个版本中则不需要.我以为Flask-WTF会自动将StringField中的文本传递到新的form实例中,但是由于某些原因,它没有.

As you can see, the form.name.data = '' line is used to clear the input field in the first version, but it's not needed in the second version. I thought Flask-WTF would automatically pass the text in StringField into the new form instance, but for some reasons, it didn't.

我的问题是:为什么在使用PRG时,不同请求之间的form.name.data不再可用?

My question is: Why form.name.data is no longer available between different requests when I use PRG?

推荐答案

由于它是一个全新的请求,它无法在重定向中传递任何内容.

It can't pass anything on a redirect, as it is a completely new request.

更多推荐

在烧瓶中发布/重定向/获取模式

本文发布于:2023-10-12 05:10:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:烧瓶   重定向   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!