在金字塔视图之间传递表单参数

编程入门 行业动态 更新时间:2024-10-17 20:33:28
本文介绍了在金字塔视图之间传递表单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个表单,要求用户在提交数据之前进行确认.我想要一个单独的确认页面,因为我需要显示很多有关如何处理表单数据的信息.我想知道是否有一种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:

  • 将数据存储在会话中.
  • 将数据以隐藏形式存储在确认页面上,然后使用已确认"重新提交
  • 我更喜欢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.)

    更多推荐

    在金字塔视图之间传递表单参数

    本文发布于:2023-11-29 16:15:03,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1646917.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:视图   表单   金字塔   参数

    发布评论

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

    >www.elefans.com

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