Commit db7b47e1df8aa2df82b3b64370b48a9ce7c72ebd
1 parent
4de8157f
Exists in
master
and in
39 other branches
Adding view to block robots
Showing
2 changed files
with
12 additions
and
1 deletions
Show diff stats
src/colab/urls.py
... | ... | @@ -12,7 +12,9 @@ admin.autodiscover() |
12 | 12 | |
13 | 13 | urlpatterns = patterns('', |
14 | 14 | url(r'^$', 'home.views.index', name='home'), |
15 | - url(r'open-data/$', TemplateView.as_view(template_name='open-data.html'), | |
15 | + url(r'^robots.txt$', 'home.views.rebots', name='robots'), | |
16 | + | |
17 | + url(r'^open-data/$', TemplateView.as_view(template_name='open-data.html'), | |
16 | 18 | name='opendata'), |
17 | 19 | |
18 | 20 | url(r'^search/', include('search.urls')), | ... | ... |
src/home/views.py
... | ... | @@ -3,6 +3,7 @@ from collections import OrderedDict |
3 | 3 | |
4 | 4 | from django.core.cache import cache |
5 | 5 | from django.shortcuts import render |
6 | +from django.http import HttpResponse, Http404 | |
6 | 7 | |
7 | 8 | from search.utils import trans |
8 | 9 | from haystack.query import SearchQuerySet |
... | ... | @@ -44,3 +45,11 @@ def index(request): |
44 | 45 | )[:6], |
45 | 46 | } |
46 | 47 | return render(request, 'home.html', context) |
48 | + | |
49 | + | |
50 | +def robots(request): | |
51 | + if settings.ROBOTS_NOINDEX: | |
52 | + return HttpResponse('User-agent: *\nDisallow: /', | |
53 | + content_type='text/plain') | |
54 | + | |
55 | + raise Http404 | ... | ... |