Taken from the longer description on my blog:
One of the great things about Django is its simple and flexible URL handling. If your Django work, like mine, includes converting existing sites, you’ll probably be doing some URL cleanup along the way...
Just plug your old/new URL pairs into redirects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from django.views.generic.simple import redirect_to
urlpatterns = patterns('',
# ...your project's patterns...
)
# Your old/new URL tuples -- examples
redirects = (
('^kawasaki/zx750f', '/bikes/kawasaki/zx750f/'), # Matching a literal URL
('^gear/[0-9]+/$', '/gear/'), # Ignoring part of the matched URL
('^foo/(?P<id>\d+)/$', '/bar/%(id)s/'), # Oooh, parameter capture!
)
for oldurl, newurl in redirects:
urlpatterns += patterns('', (oldurl, redirect_to, {'url': newurl}))
|
More like this
- Form field with fixed value by roam 1 week, 4 days ago
- New Snippet! by Antoliny0919 2 weeks, 3 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 6 months, 4 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.