Like django.contrib.redirects on steroids. Maybe.
Project description
django painless redirects
like django.contrib.redirects, on steroids. maybe.
Features
- simple redirects table, with that bit more flexibility / convenience
- django sites framework support
- wildcard matching
- explicit limit to site/domain
- explicit redirect to site
- decide if you want to keep GET vars
- move complete trees (/old/productXY to /new/productXY, with one redirect, for all products)
- force site domain middleware, that redirects to current site's domain, if not already there
Yet to be done:
- decide if to include GET vars when matching a redirect
- contrib packages with "magic" redirects for django-cms, django-filer -> SEO getting easy.
Installation
To get the latest stable release from PyPi
pip install django-painless-redirects
Add painless_redirects
to your INSTALLED_APPS
INSTALLED_APPS = (
...,
'painless_redirects',
)
Add the following middlware to MIDDLEWARE, to make basic manual redirects work.
painless_redirects.middleware.ManualRedirectMiddleware
As a rule of thumb, you'll add the middleware rather at the end of the list. If you add it more at the beginning, other redirecting middlewares will get priority - for example, you'll not be able to redirect any path without having a language slug first, when LocaleMiddleware is before our middleware.
If you want to always redirect to the domain name entered in your current site (django.contrib.sites must be installed), also add this middleware (position is not that important):
painless_redirects.middleware.ForceSiteDomainRedirectMiddleware
Compatibility
- django 1.11: should use
django-painless-redirects<0.3.6
(not supported anyway since april 2020)
Usage
Add and manage your redirects in the django admin panel, under "painless redirects" > "redirects". Check hits, check auto created redirects, enable them if needed.
Settings
PAINLESS_REDIRECTS_INDEXED_CHARFIELD_MAX_LENGTH (default: 800)
- needed for mysql (set to ~255). forces you to add'painless_redirects'
tosettings.MIGRATION_MODULES
PAINLESS_REDIRECTS_AUTO_CREATE (default: True)
- auto create redirects when a 404 is encounteredPAINLESS_REDIRECTS_AUTO_CREATE_ENABLED (default: False)
- should auto created redirects be enabled instantly? beware, enabling this feature might ruin your SEO, but could also be a real timesaver...PAINLESS_REDIRECTS_AUTO_CREATE_TO_PATH (default: '/')
- where to redirect to, when a 404 is auto createdPAINLESS_REDIRECTS_AUTO_CREATE_SITE (default: True)
- limit auto created redirects to the current site (from the django sites framework)
Development
- there is test app, available with
./manage.py runserver
. - quick tests, within your current env: ./manage.py test
- to run tests with django 1.11 / 2.0 / 2.1 / ... :
tox
Contributions
If you want to contribute to this project, please perform the following steps
.. code-block:: bash
# Fork this repository
# Clone your fork
mkvirtualenv django-painless-redirects
pip install -r test_requirements.txt
git checkout -b feature_branch
# Implement your feature and tests
git add . && git commit
git push -u origin feature_branch
# Send us a pull request for your feature branch
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-painless-redirects-0.7.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d08f665014d2ac8a4a897ae67f367b46914ac075215cd73ea52d109712227a1 |
|
MD5 | 6e4d8b5da639d376c9e7dcb81095adfc |
|
BLAKE2b-256 | 82aec7de89eff480fb906d7dd2b9fed58ec13676efffde1ba19251e98ca11eea |
Hashes for django_painless_redirects-0.7.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 499715f32fee532a27610ecf068d69433abc607490500674ddb24f3f1b5c49df |
|
MD5 | 8e267a10bca55e147adaaf85a5840ac7 |
|
BLAKE2b-256 | c3d9b73c77d048c0f7809247bb4a69481064fd705330ef4a091d2145d3828c2b |