Uma maneira comum de inicializar formulários é:
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
# Process the data in form.cleaned_data
return HttpResponseRedirect('/thanks/')
else:
form = ContactForm()
return render(request, 'contact.html', {
'form': form,
})
A melhor maneira de secar as coisas e remover uma condicional:
def contact(request):
form = ContactForm(request.POST or None)
if request.method == "POST" and form.is_valid():
# Process the data in form.cleaned_data
return HttpResponseRedirect('/thanks/')
return render(request, 'contact.html', {
'form': form,
})