python - Is there anyways to store the data from the forms into variables without saving it to the database?
问题描述
I'm trying to save the data inside a form into variables without saving it to the database but I don't know how. I'm not even sure if it's possible.
解决方案
ModelForm
除非您明确调用它,否则不会保存其中的数据save
,因此您可以自由地读取数据cleaned_data
并根据需要使用它。如果您使用的是常规表单,则仅当您通过将数据复制到实例中来创建/更新模型实例时,它才会保存到数据库中cleaned_data
。
例如:
def some_view(request):
form = MyForm(request.POST)
if form.is_valid():
foo = form.cleaned_data['foo']
# Do what you want with `foo`. Save to session, print to console, etc.
推荐阅读
- android - 在jetpack compose中找不到ProvideEmphasis
- react-native - 用于 react-native 的 SKAdNetwork 库
- python - 错误“类型对象‘图像’没有属性‘打开’
- asp.net-mvc - 尝试将数据库实体移动到另一个命名空间但出现错误:IdentityDb' context has changed - AspnetUser is changed
- html - 3 + 9 的引导列不在同一行
- substrate - make: *** 没有规则使目标“init”。停止
- python - 在 DB2 中触发 - 尝试填充 XML 列时出错
- python - 快速排序 Python 程序
- php - GRAV CMS TNTSearch 标题页覆盖
- javascript - React 中数组的条件渲染:For vs Map