Metadata-Version: 2.1
Name: django-static-redirects
Version: 0.0.0
Summary: Static redirects for Django
Author: Jake Howard
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Classifier: License :: OSI Approved
Classifier: License :: OSI Approved :: MIT License
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.1
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development
Requires-Dist: Django>=3.2
Requires-Dist: ruff ; extra == "dev"
Requires-Dist: black ; extra == "dev"
Project-URL: Changelog, https://github.com/RealOrangeOne/django-static-redirects/releases
Project-URL: Issues, https://github.com/RealOrangeOne/django-static-redirects/issues
Project-URL: Source, https://github.com/RealOrangeOne/django-static-redirects
Provides-Extra: dev

# Django Static Redirects

![CI](https://github.com/RealOrangeOne/django-static-redirects/workflows/CI/badge.svg)
![PyPI](https://img.shields.io/pypi/v/django-static-redirects.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-static-redirects.svg)
![PyPI - License](https://img.shields.io/pypi/l/django-static-redirects.svg)

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`:

```python
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.

```csv
/source,/destination,true
/source2,/destination2
```

### JSON files

JSON files must contain a list of objects:

```json
[
    {
        "source": "/source",
        "destination": "/destination",
        "is_permanent": true
    },
    {
        "source": "/source2",
        "destination": "/destination2",
    }
]
```

Much like CSV, `is_permanent` is optional, defaulting to `false`.

