On Thu, Mar 28, 2013 at 8:21 AM, Loic Bistuer <loic.bist...@sixmedia.com>wrote:

> What I would like to see:
>
> urlpatterns = patterns('',
>         # Standard patterns
>          url(r'^admin/', include(admin.site.urls)),
>
>         # Fallthrough patterns
>         url('', include('myapp.urls'),
>         url('', include('django.contrib.flatpages.urls'),
>         url('', include('django.contrib.redirects.urls'),
> )
>
> Each app minds its own business and no more middleware that juggle with
> Http404.
>

Fall through URL patterns make it less clear about what view is handling a
URL. It's already known and established that you need to check middleware
for arbitrary URL handling, adding this to the URL patterns as well doesn't
feel like a step in the right direction.

Middlewares that juggle Http404 are not all bad and have the potential of
being a bit saner and faster than a URL fall through. If the dispatcher
falls through, then every URL that matches the pattern would need to hit
the database and/or include its own caching to determine if the URL is a
hit for a specific app/view. That leads to the same bit of code duplicated
in the top of almost every one of these fall through views.

With middleware, you can put all of this shared logic in a base class and
provide the ability to completely short circuit the dispatcher for known
matches. For src.org, we have a few different models with staff defined
URLs. The traditional Http404 middleware pattern was a bit repetitive and I
solved the problem with this middleware (
https://gist.github.com/manfre/5262782). The heart of the middlware is
ContentMiddleware._process(), which contains the "was this handled" logic.
The Gist includes one of the simple arbitrary URL model handlers, but we
have quite a few more.


Regards,
Michael Manfre

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to