Access Field Values Of Form Django

[Solved] Access Field Values Of Form Django | Python Frameworks Django - Code Explorer | www.yomemimo.com
Question : Access field values of form django

Answered by : nice-nightingale-dtkz1pt4ffks

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, })

Source : https://coders911.org/questions/4706255/How-to-get-value-from-form-field-in-django-framework | Last Update : Thu, 31 Mar 22

Question : Access field values of form django

Answered by : victorious-vole-wfi7q5j6btcp

>>> data = {'subject': 'hello',
... 'message': 'Hi there',
... 'sender': '[email protected]',
... 'cc_myself': True}
>>> f = ContactForm(data)
>>> f.is_valid()
True
>>> f.cleaned_data
{'cc_myself': True, 'message': 'Hi there', 'sender': '[email protected]', 'subject': 'hello'}

Source : https://docs.djangoproject.com/en/dev/ref/forms/api/#accessing-the-fields-from-the-form | Last Update : Sat, 25 Sep 21

Answers related to Access field values of form django

Code Explorer Popular Question For Python Frameworks Django