Automating Django Redirects

Django has a very simple redirects system. Simple as in it’s easy to understand. If someone encounters a 404, Django Redirects catches this and does a final lookup to see if there’s an entry to a new URL in the redirects table.

The real win, is when your slug fields change (and thus the get_absolute_url() of your objects), you can simply automate the creation of a redirect:

Note you must have enabled the redirects app before trying this. You also need a get_absolute_url() function defined for your MyObjectClass. This is the true value of Django Middleware. Let those truly repetitive site-wide tasks get done in one spot.