Installation
Install djangocms-redirect:
pip install djangocms-redirect
Add to INSTALLED_APPS:
INSTALLED_APPS = [ ... djangocms_redirect ... ]
Add to MIDDLEWARE_CLASSES:
If you intend to use
process_request
the add it near the top (afterdjango.middleware.cache.UpdateCacheMiddleware
); if usingprocess_response
add at the bottom (beforedjango.middleware.cache.FetchFromCacheMiddleware
):MIDDLEWARE_CLASSES = [ ... djangocms_redirect.middleware.RedirectMiddleware ... ]
Choose if you want to process the redirect during the request (default) or response by setting:
DJANGOCMS_REDIRECT_USE_REQUEST = True
: during requestDJANGOCMS_REDIRECT_USE_REQUEST = False
: during response
Migrate:
python manage.py migrate
The go to http://mysite.com/admin/djangocms_redirect/
and create redirect instances.
Settings
DJANGOCMS_REDIRECT_USE_REQUEST
: IfTrue
the redirect check will be done in the request phase, to allow preempting any other logic. Beware: this will result in extra queries on each request because the redirects will be checked before the view logic triggers. IfFalse
the redirect will be checked in the response phase.DJANGOCMS_REDIRECT_CACHE_TIMEOUT
: You can provide a custom cache timeout (Default: 3600 sec)DJANGOCMS_REDIRECT_404_ONLY
: IfTrue
(the default) andDJANGOCMS_REDIRECT_USE_REQUEST=False
the redirect will be checked only for responses that return 404 (the defaultdjango.contrib.redirect
behavior). This is the lowest impact option in terms of performance and the advised configuration.