“Dostęp wartości pola formy Django” Kod odpowiedzi

Dostęp wartości pola formy 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,
    })

Nice Nightingale

Dostęp wartości pola formy Django

>>> 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'}
Victorious Vole

Odpowiedzi podobne do “Dostęp wartości pola formy Django”

Pytania podobne do “Dostęp wartości pola formy Django”

Więcej pokrewnych odpowiedzi na “Dostęp wartości pola formy Django” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu