如何从django框架的表单字段中获取值?我想在视图中执行此操作,而不是在模板中执行此操作…
在视图中处理表单的标准模式如下所示:
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, })