Getting started is as simple as: ...

    easy_install django-reroute, or
    pip install django-reroute

;)

- Mark

On Fri, Dec 10, 2010 at 4:12 PM, Mark Sandstrom
<m...@deliciouslynerdy.com>wrote:

> Hello all,
>
> This is a pretty common pattern in django:
>
> def view(request):
>     if request.method == 'GET':
>         # Do something
>     elif request.method == 'POST':
>         # Do something else
>     else:
>         return HttpResponse(status=405)
>
> The setup for GET vs POST may be very different, and the single view
> approach can become monolithic.
>
> django-reroute is a drop-in replacement for django.conf.urls.defaults that
> supports HTTP verb dispatching (and provides a few other nifty tools).
>
> Getting started is as simple as:
>
>
>
> And replacing:
>
>     from django.conf.urls.defaults import *
>
> with:
>
>     from reroute import *
>
> You can then create urlpatterns like this:
>
> paychecks = patterns('myapp.views.employees.paychecks',
>     verb_url('GET',     '^paychecks$', 'index_paychecks'),
>     verb_url('POST',    '^paychecks$', 'add_paycheck'),
> )
>
> urlpatterns = patterns('myapp.views.employees',
>     verb_url('GET',     '^employees$', 'index_employees'),
>     verb_url('POST',    '^employees$', 'add_employee'),
>
>     verb_url('GET',     '^employees/(?P<employee_id>\d+)$',
> 'show_employee')
>     verb_url('PUT',     '^employees/(?P<employee_id>\d+)$',
> 'update_employee')
>     verb_url('DELETE',  '^employees/(?P<employee_id>\d+)$',
> 'delete_employee'),
>
>     url('^employees/(?P<employee_id>\d+)/', include(paychecks)),
> )
>
> This is just one use case.
>
> Check out the full documentation on github:
> http://github.com/dnerdy/django-reroute
>
> Enjoy!
>
> - Mark
>
>
>

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

Reply via email to