B
B
bbquite2021-10-25 11:29:36
Django
bbquite, 2021-10-25 11:29:36

How to remove django robots.txt redirect?

You need to remove the redirect from /robots.txtto /robots.txt/
I read in the documentation about the decorator no_append_slash , but for some reason this does not work:

@no_append_slash
def robots(request, *args, **kwargs):
    return HttpResponse(
       site_settings.robots_txt,
        content_type='text/plain')

urlpatterns = [
    path('robots.txt/', views.robots, name='robots'),
    path('sitemap.xml/', sitemap, {'sitemaps': views.sitemaps}, name='django.contrib.sitemaps.views.sitemap'),
]

C sitemap.xml everything works correctly, does not redirect

Tried to do it throughre_path
re_path(r'^testlink$', views.robots, name='robots'),
re_path(r'^robots\.txt$', views.robots, name='robots'),


testlink - - works without
robots.txt redirect -- still redirects

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question