Skip to main content

Django Env Robots (.txt)

Serve different robots.txt from your production | stage | etc servers by setting environment variables. Rules are managed via templates. By default it excludes robots entirely.

Installation

Install from PyPI:

pip install django-env-robots

Then add the following to your project's INSTALLED_APPS.

'django_env_robots',

Usage

settings.py

Set the following:

  • SERVER_ENV identifies the nature of the server and thus the robots.txt template that will be used.

E.g:

SERVER_ENV = 'production'

urls.py

from django_env_robots import urls as robots_urls
...
urlpatterns = [
    path("robots.txt", include(robots_urls)),
]

robots templates

Create corresponding template files for each SERVER_ENV you will be using. These live in your projects templates directory in a robots subfolder.

For example, if SERVER_ENV can be production or stage, then create:

  • templates/robots/production.txt
  • templates/robots/stage.txt

e.g:

User-agent: *
Disallow: /admin/

Sitemap: https://www.example.com/sitemap.xml
Sitemap: https://www2.example.com/sitemap.xml

Other considertions

A robots.txt being served from a Whitenose public directory will win over this app. That is because of whitenoise's middleware behaviour - quite correct but watch out for that.

Release files for django-env-robots 0.0.5

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-env-robots 0.0.5
File Size Uploaded
django_env_robots-0.0.5.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-env-robots 0.0.5
File Interpreter ABI Platform
django_env_robots-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / django_env_robots-0.0.5.tar.gz

Download URL django_env_robots-0.0.5.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a7755a95b342bfd44f981629bbc6d95a5bc88e2d4676308c8a443982628d9f51
BLAKE2b-256 checksum
How to use checksums
67b624b3f6118a20d06e3ebc060187290b04d0cc16165e0de04b57858180fe8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / django_env_robots-0.0.5-py3-none-any.whl

Download URL django_env_robots-0.0.5-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc8ff6418197ee64c43b7062a1d8fc0045a7cd161e90056f2145661507a9b2f6
BLAKE2b-256 checksum
How to use checksums
f5e8025fb002b19faa56aad69553c9907166e78cefebcbe52c33881d06b1f0e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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