Serve up a robots.txt file in Django with the proper mime type and a full URL link to sitemap.xml
Python
Latest commit b2d2bbb Feb 23, 2016 @jbergantine Updated python requirements
- Removed Py 3.2
- Removed Py 2.6

README.rst

Django Robots

https://travis-ci.org/jbergantine/django-robots.svg?branch=develop

View builds on TravisCI.

Installation from Source

$ git clone git@github.com:jbergantine/django-robots.git
$ cd django-robots
$ python setup.py install

Installation via PIP Requirements File

Include in the PIP requirements file the following line:

-e git://github.com/jbergantine/django-robots.git#egg=django_robots

And then install as normal (IE:)

$ pip install -r path/to/requirements/file.txt

Testing

$ python setup.py test

With TOX

First, install Tox, then run the tests. This will test against the Django versions specified in the environments specified in the tox.ini file

$ pip install tox
$ tox

Setup the Project For the Application

Add to the project's settings.py file tuple of installed apps:

'django_robots',

In the project's urls.py file add:

url(r'^robots.txt', include('django_robots.urls')),

Enable the sites framework in the project's settings.py file:

  1. Add 'django.contrib.sites' to your INSTALLED_APPS setting.
  2. Define a SITE_ID setting:
SITE_ID = 1
  1. Run syncdb.

From the Django Admin, configure the Domain Name and Display Name for the site, the domain name will be used in the robots.txt file to point to the absolute URL of the site's sitemap.xml file.

Configure the robots.txt Template

By default the robots.txt template only includes a directive to point to the sitemap at http://site_url/sitemap.xml. This should be removed if the site doesn't have an XML sitemap for some reason. If you're using virtualenv, to copy the templates from the project in order to make adjustments to them, cd to the root of the django project and execute the following command:

cp -r ../src/django-robots/django_robots/templates/robots templates/robots

Template Tags Installed

current_site_url

Returns a full URL for the current site including custom protocol and port if set (i.e. https://example.com:8080).

Example usage:

{% load current_site_url %}
{% current_site_url %}