Skip to main content

Django X-Robots-Tag Middleware

PyPi Package Version Python package codecov

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

  1. Add the middleware to MIDDLEWARE in your settings.py:

    MIDDLEWARE = [
        # ...
        "x_robots_tag_middleware.middleware.XRobotsTagMiddleware",
    ]
    
  2. Add X_ROBOTS_TAG to your settings.py with 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_TAG is 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)

Source distribution for django-x-robots-tag-middleware 2.0.0
File Size Uploaded
django_x_robots_tag_middleware-2.0.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-x-robots-tag-middleware 2.0.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

1 release file

1.3

1 release file

1.2

1 release file

1.1

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page