django-static-redirects


Namedjango-static-redirects JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryStatic redirects for Django
upload_time2024-03-12 10:16:47
maintainer
docs_urlNone
authorJake Howard
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Static Redirects

![CI](https://github.com/torchbox/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",
    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.

```csv
/source,/destination,true
/source2,/destination2
https://example.com/source3,/destination3
```

### JSON files

JSON files must contain a list of objects:

```json
[
    {
        "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`.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-static-redirects",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Jake Howard",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/bf/2a/d0e02d4e1467c9b904b874c273a2b031f4b634a514dec00e2b1a4c4c1caf/django_static_redirects-1.0.0.tar.gz",
    "platform": null,
    "description": "# Django Static Redirects\n\n![CI](https://github.com/torchbox/django-static-redirects/workflows/CI/badge.svg)\n![PyPI](https://img.shields.io/pypi/v/django-static-redirects.svg)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-static-redirects.svg)\n![PyPI - License](https://img.shields.io/pypi/l/django-static-redirects.svg)\n\nDefine redirects in your repository as either CSV of JSON files, and have Django performantly serve them.\n\nRedirect matching is designed to be as fast as possible, and does not use the database.\n\n## Installation\n\n```\npip install django-static-redirects\n```\n\nThen, add `static_redirects` to `INSTALLED_APPS`.\n\nThe 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.\n\n## Usage\n\nTo add files containing redirects, set them in `STATIC_REDIRECTS`:\n\n```python\nSTATIC_REDIRECTS = [\n    BASE_DIR / \"static-redirect.csv\",\n    BASE_DIR / \"static-redirect.json\",\n]\n```\n\nRedirect files are read in-order, with latter redirects taking precedence.\n\nRedirects 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.\n\n### CSV files\n\nCSV 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.\n\n```csv\n/source,/destination,true\n/source2,/destination2\nhttps://example.com/source3,/destination3\n```\n\n### JSON files\n\nJSON files must contain a list of objects:\n\n```json\n[\n    {\n        \"source\": \"/source\",\n        \"destination\": \"/destination\",\n        \"is_permanent\": true\n    },\n    {\n        \"source\": \"/source2\",\n        \"destination\": \"/destination2\",\n    },\n    {\n        \"source\": \"/source3\",\n        \"destination\": \"/destination3\",\n        \"hostname\": \"example.com\"\n    },\n    {\n        \"source\": \"https://example.com/source4\",\n        \"destination\": \"/destination4\",\n    }\n]\n```\n\nMuch like CSV, `is_permanent` is optional, defaulting to `false`.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Static redirects for Django",
    "version": "1.0.0",
    "project_urls": {
        "Changelog": "https://github.com/torchbox/django-static-redirects/releases",
        "Issues": "https://github.com/torchbox/django-static-redirects/issues",
        "Source": "https://github.com/torchbox/django-static-redirects"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13c95e64bc82b58078cc9e0944428a4d4802d2097289cfff93a7fefbbb2e334a",
                "md5": "f261db585b1b4269cd5cffa69aa85244",
                "sha256": "2dbb259aedc1301426c15510e551385ebad6fc1c4b5250155c5e242150a38c6f"
            },
            "downloads": -1,
            "filename": "django_static_redirects-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f261db585b1b4269cd5cffa69aa85244",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6332,
            "upload_time": "2024-03-12T10:16:46",
            "upload_time_iso_8601": "2024-03-12T10:16:46.824389Z",
            "url": "https://files.pythonhosted.org/packages/13/c9/5e64bc82b58078cc9e0944428a4d4802d2097289cfff93a7fefbbb2e334a/django_static_redirects-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bf2ad0e02d4e1467c9b904b874c273a2b031f4b634a514dec00e2b1a4c4c1caf",
                "md5": "39e04cb0eae08bb0436b5e9c86098380",
                "sha256": "4f6b234fc62792d4bd02f6acfe2aa37d979910183016e645191ffc3dabb4d4a7"
            },
            "downloads": -1,
            "filename": "django_static_redirects-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "39e04cb0eae08bb0436b5e9c86098380",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10139,
            "upload_time": "2024-03-12T10:16:47",
            "upload_time_iso_8601": "2024-03-12T10:16:47.859092Z",
            "url": "https://files.pythonhosted.org/packages/bf/2a/d0e02d4e1467c9b904b874c273a2b031f4b634a514dec00e2b1a4c4c1caf/django_static_redirects-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 10:16:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "torchbox",
    "github_project": "django-static-redirects",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-static-redirects"
}
        
Elapsed time: 1.84174s