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",
BASE_DIR / "static-redirect.json",
]
Redirect files are read in-order, with latter redirects taking precedence.
Redirects can either be just paths, in which case they match all hostnames, or include a hostname. Schemes are not included as part of the match. If a request contains a querystring, it is ignored, unless a match containing the querystring is found.
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
https://example.com/source3,/destination3
JSON files
JSON files must contain a list of objects:
[
{
"source": "/source",
"destination": "/destination",
"is_permanent": true
},
{
"source": "/source2",
"destination": "/destination2",
},
{
"source": "/source3",
"destination": "/destination3",
"hostname": "example.com"
},
{
"source": "https://example.com/source4",
"destination": "/destination4",
}
]
Much like CSV, is_permanent is optional, defaulting to false.
Metadata
Release files for django-static-redirects 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_static_redirects-1.0.0.tar.gz | 10.1 kB | Without provenance | Details for django_static_redirects-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_static_redirects-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_static_redirects-1.0.0-py3-none-any.whl |
Total release size: 16.5 kB
Release files / django_static_redirects-1.0.0.tar.gz
| Download URL | django_static_redirects-1.0.0.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f6b234fc62792d4bd02f6acfe2aa37d979910183016e645191ffc3dabb4d4a7
|
|
BLAKE2b-256 checksum How to use checksums |
bf2ad0e02d4e1467c9b904b874c273a2b031f4b634a514dec00e2b1a4c4c1caf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / django_static_redirects-1.0.0-py3-none-any.whl
| Download URL | django_static_redirects-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2dbb259aedc1301426c15510e551385ebad6fc1c4b5250155c5e242150a38c6f
|
|
BLAKE2b-256 checksum How to use checksums |
13c95e64bc82b58078cc9e0944428a4d4802d2097289cfff93a7fefbbb2e334a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for django-static-redirects 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.