From 5f0266a211518155384c3148dd548eabba404aee Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 29 Sep 2013 21:06:11 +0200 Subject: [PATCH] serve /robots.txt --- nsupdate/main/urls.py | 4 +++- nsupdate/main/views.py | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index 2cf3e2a..5366158 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -1,7 +1,8 @@ from django.conf.urls import patterns, url from django.views.generic import TemplateView from main.views import ( - HomeView, OverviewView, HostView, DeleteHostView, AboutView, HelpView, GenerateSecretView) + HomeView, OverviewView, HostView, DeleteHostView, AboutView, HelpView, GenerateSecretView, + RobotsTxtView, ) from api.views import ( MyIpView, DetectIpView, NicUpdateView, AuthorizedNicUpdateView) @@ -23,4 +24,5 @@ urlpatterns = patterns( url(r'^nic/update$', NicUpdateView), url(r'^nic/update_authorized$', AuthorizedNicUpdateView, name='nic_update_authorized'), + url(r'^robots.txt$', RobotsTxtView), ) diff --git a/nsupdate/main/views.py b/nsupdate/main/views.py index ebe5710..b83f897 100644 --- a/nsupdate/main/views.py +++ b/nsupdate/main/views.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django.views.generic import TemplateView, CreateView from django.views.generic.edit import UpdateView, DeleteView -from django.http import HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required from django.contrib import messages from django.utils.decorators import method_decorator @@ -152,3 +152,21 @@ class DeleteHostView(DeleteView): context['nav_overview'] = True context['hosts'] = Host.objects.filter(created_by=self.request.user) return context + + +def RobotsTxtView(request): + """ + Dynamically serve robots.txt content. + If you like, you can optimize this by statically serving this by your web server. + + :param request: django request object + :return: HttpResponse object + """ + content = """\ +User-agent: * +Crawl-delay: 10 +Disallow: /accounts/ +Disallow: /myip/ +Disallow: /nic/update/ +""" + return HttpResponse(content, content_type="text/plain")