Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Loading Robots.txt through generic views

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.

like image 363
Uma Avatar asked Jan 03 '15 19:01

Uma


1 Answers

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.

like image 88
Uma Avatar answered Oct 04 '22 02:10

Uma