Django X-Robots-Tag Middleware
Simple Django middleware to send the X-Robots-Tag header on all responses. Useful for
ensuring a site in development is not accidentally picked up and indexed until it is ready.
Works under both WSGI and ASGI, and is fully type annotated.
Requirements
- Python 3.10+
- Django 5.2+
Installation
From PyPI:
$ python -m pip install django-x-robots-tag-middleware
Usage
-
Add the middleware to
MIDDLEWAREin yoursettings.py:MIDDLEWARE = [ # ... "x_robots_tag_middleware.middleware.XRobotsTagMiddleware", ]
-
Add
X_ROBOTS_TAGto yoursettings.pywith the directives you want:X_ROBOTS_TAG = ["noindex", "nofollow"]
The setting may be a list of directives (joined with commas) or a plain string:
X_ROBOTS_TAG = "noindex, nofollow"
If
X_ROBOTS_TAGis unset,None, or empty, no header is added — so you can enable the header per environment without changing your middleware list:# settings/staging.py X_ROBOTS_TAG = ["noindex", "nofollow"] # settings/production.py X_ROBOTS_TAG = None
Details about the values for the tag and what they do can be found in the Google documentation.
Development
This project uses uv for packaging and dependency
management (with the uv_build backend) and Ruff for
linting and formatting.
$ uv sync --group dev # create .venv from uv.lock
$ uv run python manage.py test # run the test suite
$ uv run coverage run manage.py test # ...with coverage
$ uv run coverage report
$ uv run ruff check . && uv run ruff format .
$ uv build # build the sdist and wheel
To test against a specific Django version:
$ uv pip install "Django~=6.0.0"
$ uv run --no-sync python manage.py test
Optionally, install the pre-commit hooks:
$ uvx pre-commit install
The tests run against the x_robots_tag_middleware_demo project included in this repo.
License
MIT — see LICENSE.
Release files for django-x-robots-tag-middleware 2.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 | |
|---|---|---|---|
| django_x_robots_tag_middleware-2.0.0.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_x_robots_tag_middleware-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 kB
Release files / django_x_robots_tag_middleware-2.0.0.tar.gz
| Download URL | django_x_robots_tag_middleware-2.0.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b859cac07e2ae806456e4ca8c78fa771cfdbb7121d5b3eb9724f7693a914ee43
|
|
BLAKE2b-256 checksum How to use checksums |
697f961d81091afc9ad2b0e298ea5293b297682464f2e9eee515454b9f580fc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.
Transparency logRelease files / django_x_robots_tag_middleware-2.0.0-py3-none-any.whl
| Download URL | django_x_robots_tag_middleware-2.0.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca6f3ac66eb144088ee721b509172547f6f5b09453f177c82e8b3e2e7fc595a9
|
|
BLAKE2b-256 checksum How to use checksums |
63e02079eea97f8d8ccdb4f0e664d992e75461b2d632f4e2a22a6546e8652543
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.
Transparency log