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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 8 months ago
Comments
Please login first before commenting.