Static redirects for Django
Project description
Django Static Redirects
Define redirects in your repository as either CSV of JSON files, and have Django performantly serve them.
Redirect matching is designed to be as fast as possible, and does not use the database.
Installation
pip install django-static-redirects
Then, add static_redirects
to INSTALLED_APPS
.
The redirect is done as a middleware. Add static_redirects.StaticRedirectsMiddleware
wherever makes sense for you in MIDDLEWARE
- ideally below any middleware which modify the response (eg GzipMiddleware
) but above anything especially intensive, so the redirects are applied before them.
Usage
To add files containing redirects, set them in STATIC_REDIRECTS
:
STATIC_REDIRECTS = [
BASE_DIR / "static-redirect.csv",
]
Redirect files are read in-order, with latter redirects taking precedence.
CSV files
CSV files must contain 2 or 3 columns, without a header. The first column is the source path, second is the destination URL, and the (optional) third notes whether the redirect is permanent.
/source,/destination,true
/source2,/destination2
JSON files
JSON files must contain a list of objects:
[
{
"source": "/source",
"destination": "/destination",
"is_permanent": true
},
{
"source": "/source2",
"destination": "/destination2",
}
]
Much like CSV, is_permanent
is optional, defaulting to false
.
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
File details
Details for the file django_static_redirects-0.0.0.tar.gz
.
File metadata
- Download URL: django_static_redirects-0.0.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee5d2c2aab0f09a346dae057b5ee35b0197816377de6196a17091838c6fb2b5f |
|
MD5 | 029d9062f1cfa482eccf7380969c1514 |
|
BLAKE2b-256 | dafaf4f88143c9b8674a302524e05537a6470f3c1f905971afffea51ad79ba36 |
File details
Details for the file django_static_redirects-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_static_redirects-0.0.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aa823325252b5baeffb4ba7dce79f5a24e7189185a0f0978114db76fff4347a |
|
MD5 | 4c292978be02cea1830697955482b378 |
|
BLAKE2b-256 | e3c2a9004aa51bb86083a385ee1fa4bd8fb9335073c2f1487dd09ffc1ab15312 |