Sunday, 18 August 2013

how to create an "all-others" url pattern in django?

how to create an "all-others" url pattern in django?

In my django site, I have four views: index, foo, bar, and backstop.
If I'm asked for the / url, I want to use the index view
If I get a url like /foo/123, I want to use the foo view.
If I get a url like /bar/123, I want to use the bar view.
if I get any other url, I want to call the backstop view. (so it could be
/backstop, /baz/123, /some/other/path, /zipidee/doo/dah/)
I've tried a few variations on:
url ('/foo', 'myapp.views.foo'),
url ('/bar', 'myapp.views.bar'),
url ('/', 'myapp.views.index),
url ('.*', 'myapp.views.backstop')
But I either seem to end up getting the index for everything, or the
backstop for everything.
Someone must have done this before...

No comments:

Post a Comment