I've got a URLs pattern like this:
urlpatterns = (
url(r'^$', list_titles, name='list'),
url(r'^(?P<tag>[a-z\-0-9]+?)/$', list_titles, name='filtered-list'),
url(r'^(?P<title>\S+?)/$', show_title, name='title'),
)
The filtered-list
and title
match the same things.
If there is is a available list of things matching the tag
in filtered-list
, I want list_titles
to fire off. But if there isn't an matching tag
, I want to bubble that back to the URL processor so show_title fires off.
If there's no matching title, I'll raise a proper 404 there.
I have a feeling this might have something to do with signals... But I've never used them before, so I could be completely off on that =)
Note: I know I can do this from inside the view... But it's a bit smelly having to hard-wire the process into the view. I'd like the URL order to decide what gets chosen first and what it hands off to.
Edit: I'm an idiot.
This is exactly what happens by default! As long as you have a proper match. My show_title
method was missing its title
argument so the third URL wasn't being passed in properly.
Ok, so a slightly modified question: knowing now that there is exception handling built into it, would it be more efficient for me to manually pass the request to show_title
(from within list_titles
, or would it be, on balance, better to leave the urlpatterns handling things?
Edit2: Revenge of the idiot
Turns out it doesn't do this at all. I accidentally modified the first pattern so it wasn't matching at all, and thought it was handing off to the detail view. One of those days, I'm afraid.