From efad908ebf06d52fca6302a30a4ccd86885de493 Mon Sep 17 00:00:00 2001 From: Allyn Treshansky Date: Fri, 27 Feb 2026 13:08:33 +0000 Subject: [PATCH] Added a robots.txt file --- config/settings/base.py | 1 + config/templates/robots.txt | 4 ++++ config/urls.py | 6 ++++++ grumpy/core/tests/test_urls.py | 8 ++++++++ 4 files changed, 19 insertions(+) create mode 100644 config/templates/robots.txt create mode 100644 grumpy/core/tests/test_urls.py diff --git a/config/settings/base.py b/config/settings/base.py index 085dd8d..b55bd83 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -147,6 +147,7 @@ "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [ str(ROOT_DIR / "grumpy/core/templates"), + str(ROOT_DIR / "config/templates"), ], # 'APP_DIRS': True, # not needed since "app_directories.Loader" is specified below "OPTIONS": { diff --git a/config/templates/robots.txt b/config/templates/robots.txt new file mode 100644 index 0000000..8955fdd --- /dev/null +++ b/config/templates/robots.txt @@ -0,0 +1,4 @@ +# robots.txt + +User-Agent: * +Disallow: / \ No newline at end of file diff --git a/config/urls.py b/config/urls.py index c386ac8..b658dea 100644 --- a/config/urls.py +++ b/config/urls.py @@ -11,6 +11,7 @@ from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path +from django.views.generic import TemplateView # from allauth.account.decorators import secure_admin_login @@ -48,6 +49,11 @@ ################# urlpatterns = [ + # robots.txt + path( + "robots.txt", + TemplateView.as_view(template_name="robots.txt", content_type="text/plain"), + ), # admin... path("admin/", admin.site.urls), # auth... diff --git a/grumpy/core/tests/test_urls.py b/grumpy/core/tests/test_urls.py new file mode 100644 index 0000000..8c520b7 --- /dev/null +++ b/grumpy/core/tests/test_urls.py @@ -0,0 +1,8 @@ +from http import HTTPStatus + +def test_robots_txt(client): + + response = client.get("/robots.txt") + assert response.status_code == HTTPStatus.OK + assert response["content-type"] == "text/plain" + assert response.content.startswith(b"# robots.txt\n") \ No newline at end of file