heya,

*Disclaimer: This is about the the Django Docs, and a possible suggestion 
for it - apologies if this isn't the correct group (but I didn't think it 
quite fell into django-users).
*

The official Django Docs for forms offers up the following pattern for Form 
view code:

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
>             # ...
>             return HttpResponseRedirect('/thanks/') # Redirect after POST
>     else:
>         form = ContactForm() # An unbound form
>     return render_to_response('contact.html', {
>         'form': form,
>     })


https://docs.djangoproject.com/en/dev/topics/forms/

I was just viewing a talk by pydanny and Miguel Araujo at DjangoCon US 2011 
on "Advanced Django Form Usage", and they offered up what they seem to feel 
was a better pattern for form viewcode:

def some_view(request, template_name="someapp/someform.html")
>     form = MyForm(request.POST or None)
>     if form.is_valid():
>         do_x()
>         return redirect('Home')
>     return render(request, template_name {'form': form}).


http://speakerdeck.com/u/pydanny/p/advanced-django-forms-usage (Slide 13)

Now, apart from being shorter, I don't think I know enough about Django or 
forms to know which one is actually "better" overall. However, what's the 
community's consensus on this?

If it is better, is there any scope for having it in the official Django 
docs? Or even adding it as an alternative approach, and discussing the 
pros/cons?

Cheers,
Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/elI_Os49thcJ.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to