Skip to main content

Control robots.txt files from environment variables and templates.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_env_robots-0.0.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

django_env_robots-0.0.5-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django_env_robots-0.0.5.tar.gz.

File metadata

  • Download URL: django_env_robots-0.0.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for django_env_robots-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a7755a95b342bfd44f981629bbc6d95a5bc88e2d4676308c8a443982628d9f51
MD5 ac0b1f45205b20d5ee5d7e3547d1e7a0
BLAKE2b-256 67b624b3f6118a20d06e3ebc060187290b04d0cc16165e0de04b57858180fe8e

See more details on using hashes here.

File details

Details for the file django_env_robots-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_env_robots-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8ff6418197ee64c43b7062a1d8fc0045a7cd161e90056f2145661507a9b2f6
MD5 9f6e7c425c6f2b89e81ab51c5878170d
BLAKE2b-256 f5e8025fb002b19faa56aad69553c9907166e78cefebcbe52c33881d06b1f0e0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page