gpt4 book ai didi

python - 如何从 django 框架中的表单字段中获取值(value)?

转载 作者:IT老高 更新时间:2023-10-28 21:10:20 25 4
gpt4 key购买 nike

如何从 django 框架中的表单字段中获取值?我想在 View 中执行此操作,而不是在模板中...

最佳答案

Using a form in a view解释得差不多了。

The standard pattern for processing a form in a view looks like this:

def contact(request):
if request.method == 'POST': # If the form has been submitted...
form = ContactForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
# ...

print form.cleaned_data['my_form_field_name']

return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = ContactForm() # An unbound form

return render_to_response('contact.html', {
'form': form,
})

关于python - 如何从 django 框架中的表单字段中获取值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4706255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com