If I put this in my view:
if slug == 'old-path':
return HttpResponsePermanentRedirect('new-path')
it skips my slugbased view and returns 404.
How do I easily return 301 and "reprocess" my view so I don't get a 404?
EDIT
@Pydev UAs comment was the correct answer in this case, but I appreciated the detailed answer by John Debs, which gave me the hint to look into named urls, which I didn't know about. Thanks all.
Add
from django.core.urlresolvers import reverseto your list of imports and then try this bit of code:The problem you had was that
HttpResponsePermanentRedirect()needs a path but you were providing it with a slug.reverse()will search through your named URLs for the string you provide and return a path, which can then be redirected to properly.