在 Django 表单中存储动态字段 [英] Storing dynamic fields in Django forms
问题描述
Django 的表单库具有表单集功能,允许您处理动态添加的表单.例如,如果您的应用程序有一个书签列表,您将使用表单集,您可以使用表单集来处理多个表单,每个表单代表一个书签.
Django's form library has a feature of form sets that allow you to process dynamically added forms. For example you would use form sets if your application has a list of bookmarks you could use form sets to process multiple forms that each represent a bookmark.
如果您想在表单中动态添加字段怎么办?一个例子是调查创建页面,您可以在其中动态添加无限数量的问题.你如何在 Django 中处理这个问题?
What about if you want to dynamically add a field to a form? An example would be a survey creation page where you can dynamically add an unlimited number of questions. How do you handle this in Django?
推荐答案
看看 Django 的原始创始人之一 Jacob Kaplan-Moss 最近发表的这篇文章:"动态表单生成".它使用一个示例逐步向您展示该过程.很棒的阅读.
Look at this recent post by Jacob Kaplan-Moss, one of the original founders of Django: "Dynamic form generation". It uses an example to show you the process step by step. Great read.
还有 James Bennett 于 2008 年发表的文章,Django 的发布经理.
There is also a 2008 article by James Bennett, Django's release manager.
这篇关于在 Django 表单中存储动态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!