From 28185736a3c6232012c94ad66322f44671a71349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Fri, 23 Feb 2024 11:00:22 +0100 Subject: [PATCH] Add robots.txt --- feeds/urls.py | 2 ++ feeds/views.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/feeds/urls.py b/feeds/urls.py index 1bb9f8b..bc321ba 100644 --- a/feeds/urls.py +++ b/feeds/urls.py @@ -1,6 +1,7 @@ from __future__ import annotations from django.urls import URLPattern, path +from django.views.decorators.cache import cache_page from feeds import views @@ -15,6 +16,7 @@ urlpatterns: list[URLPattern] = [ path(route="add", view=views.AddView.as_view(), name="add"), path(route="upload", view=views.UploadView.as_view(), name="upload"), path(route="api/", view=APIView.as_view(), name="api"), + path(route="robots.txt", view=cache_page(timeout=60 * 60 * 365)(views.RobotsView.as_view()), name="robots"), ] # Account urls diff --git a/feeds/views.py b/feeds/views.py index dd720d8..414c027 100644 --- a/feeds/views.py +++ b/feeds/views.py @@ -259,3 +259,14 @@ class APIView(View): "title": "API Documentation", } return HttpResponse(content=template.render(context=context, request=request)) + + +class RobotsView(View): + """Robots.txt view.""" + + def get(self, request: HttpRequest) -> HttpResponse: # noqa: ARG002 + """Load the robots.txt file.""" + return HttpResponse( + content="""User-agent: *\nDisallow: /add\nDisallow: /upload\nDisallow: /accounts/""", + content_type="text/plain", + )