From db7b47e1df8aa2df82b3b64370b48a9ce7c72ebd Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Fri, 20 Dec 2013 17:54:37 -0200 Subject: [PATCH] Adding view to block robots --- src/colab/urls.py | 4 +++- src/home/views.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/colab/urls.py b/src/colab/urls.py index dd894d3..3fe8643 100644 --- a/src/colab/urls.py +++ b/src/colab/urls.py @@ -12,7 +12,9 @@ admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'home.views.index', name='home'), - url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'), + url(r'^robots.txt$', 'home.views.rebots', name='robots'), + + url(r'^open-data/$', TemplateView.as_view(template_name='open-data.html'), name='opendata'), url(r'^search/', include('search.urls')), diff --git a/src/home/views.py b/src/home/views.py index 404e23f..dfa371c 100644 --- a/src/home/views.py +++ b/src/home/views.py @@ -3,6 +3,7 @@ from collections import OrderedDict from django.core.cache import cache from django.shortcuts import render +from django.http import HttpResponse, Http404 from search.utils import trans from haystack.query import SearchQuerySet @@ -44,3 +45,11 @@ def index(request): )[:6], } return render(request, 'home.html', context) + + +def robots(request): + if settings.ROBOTS_NOINDEX: + return HttpResponse('User-agent: *\nDisallow: /', + content_type='text/plain') + + raise Http404 -- libgit2 0.21.2