在金字塔视图之间传递表单参数 [英] Passing form parameters between views in Pyramid

查看:77
本文介绍了在金字塔视图之间传递表单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个表单,要求用户在提交数据之前进行确认.我想要一个单独的确认页面,因为我需要显示很多有关如何处理表单数据的信息.我想知道是否有一种pythonic方式在Pyramid中的表单之间传递数据.

I am creating a form that requires user confirmation before submitting the data. I would like a seperate confirmation page because I need to display quite a bit information about how the form data will be processed. I was wondering if there was a pythonic way to pass data between forms in Pyramid.

提交表单会将用户带到确认页面.因此,用于确认的视图具有存储在request.POST中的表格数据.我想知道一旦用户在确认页面上点击提交",是否有一种干净的方法可以将所有这些数据传递到最终视图.我还想向参数字典中添加一个布尔变量(确认).

Submitting the form takes the user to the confirmation page. Thus, the view for the confirmation has the form data stored in request.POST. I was wondering if there was a clean way to pass along all of this data to the final view once the user hits 'submit' on the confirmation page. I would also like to add a boolean variable, confirmed, to the dictionary of parameters.

推荐答案

这不是特定于金字塔的答案,但是解决此问题的两种常见方法是:

This is not a Pyramid-specific answer, but two common approaches to this problem are:

  1. 将数据存储在会话中.
  2. 将数据以隐藏形式存储在确认页面上,然后使用已确认"重新提交

我更喜欢2,因为这是一种无状态方法.您还可以使用完全相同的表单处理逻辑,只需检查已确认"的POST变量是否存在,即可决定要采取和查看要显示的操作(即请确认"视图,或处理和已处理"视图.)

I like 2 much better because it's a stateless method. You can also use the exact same form processing logic, and just check for the presence of your "confirmed" POST variable to decide which action to take and view to show (i.e, either the "please confirm" view, or processing and the "processed" view.)

这篇关于在金字塔视图之间传递表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆