Skip to content

Commit

Permalink
Merge pull request #474 from Hexlet/sitemap
Browse files Browse the repository at this point in the history
fix robots view
  • Loading branch information
sgmdlt authored Oct 21, 2024
2 parents 3145b48 + 82ada94 commit 75efb12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.conf import settings
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.views import serve
from django.urls import include, path
from django.views.i18n import JavaScriptCatalog

from contributors.admin.custom import site
from contributors.sitemap import sitemaps
from contributors.views import robots


def trigger_error(request):
Expand All @@ -21,7 +21,7 @@ def trigger_error(request):
path('auth/', include('auth.urls')),
path('', include('contributors.urls')),
path('sentry-debug/', trigger_error),
path('robots.txt', serve, {'path': 'robots.txt'}),
path('robots.txt', robots.RobotsTxtView.as_view(), name='robots_txt'),
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
]
Expand Down
16 changes: 16 additions & 0 deletions contributors/views/robots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.http import HttpResponse
from django.template import loader
from django.views.generic import TemplateView


class RobotsTxtView(TemplateView):
template_name = "robots.txt"
content_type = "text/plain"

def render_to_response(self, context, **response_kwargs):
template = loader.get_template(self.template_name)
response = HttpResponse(
template.render(context, self.request),
content_type=self.content_type
)
return response
File renamed without changes.

0 comments on commit 75efb12

Please sign in to comment.