Last Updated: February 25, 2016
·
840
· gamebit07

Serving robots.txt in django1.5

You could have served robots.txt in django<1.5 as follows :

url(r'^robots\.txt$', direct_to_template, {'template': 'robots.txt', 'mimetype': 'text/plain'}),

1.5 onwards, directtotemplate has been depricated, to directly serve it from urls.py use the following snippet:

from django.views.generic import TemplateView
url('^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),