About Plain Text Views
Here's an example of a plain-text view for pages like robots.txt
:
from django.views.generic import TemplateView
class PlainTextView(TemplateView):
content_type = "text/plain; charset=utf-8"
You can include it in your urls.py
as follows:
urlpatterns = [
path(
"robots.txt",
PlainTextView.as_view(template_name="meta/robots.txt"),
name="robots_txt",
),
# ...
]
Tips and Tricks Programming Django 5.2 Django 4.2 Django 3.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You