7

I have uploaded robots.txt into my templates directory on my production server. I am using generic views;

from django.views.generic import TemplateView

(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),

However, when I load robots.txt on the browser I get a 404 - Page not found.

Can someone suggest what needs to be done to fix this. Thanks.

I should point out that on the local environment this seems to be working.

Uma
  • 689
  • 2
  • 12
  • 35

1 Answers1

14

Finally got it. I had to add a '/' in ^robots.txt$

(r'^robots\.txt/$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),

That's elementary! I presumed that by default APPEND_SLASH it True however, on the production server it didn't work.

Let me know if anyone can provide some insights on it.

Uma
  • 689
  • 2
  • 12
  • 35
  • 1
    Using `APPEND_SLASH = False` in your app's settings fixes that without having to add a trailing slash to your URL. See: https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-APPEND_SLASH – Yoone Nov 19 '15 at 05:26