Risposte:
Usa le viste generiche basate sulla classe ma registrati con il modello django 2.0+.
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
path('foo/', TemplateView.as_view(template_name='foo.html'))
]
https://docs.djangoproject.com/en/2.0/ref/class-based-views/base/#templateview
Usa le viste generiche basate sulla classe.
from django.views.generic import TemplateView
urlpatterns = patterns('',
(r'^foo/$', TemplateView.as_view(template_name='foo.html')),
)
urlpatterns = patterns('django.views.generic.simple',
(r'^foo/$', 'direct_to_template', {'template': 'foo_index.html'}),
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail.html'}),
)
Un ulteriore aggiornamento per le versioni più recenti e incluso il tipo MIME da questo sito:
http://www.techstricks.com/adding-robots-txt-to-your-django-project/
from django.conf.urls import url
from django.views.generic import TemplateView
urlpatterns = [
#... your project urls
url(r'^robots.txt$', TemplateView.as_view(template_name="robots.txt", content_type="text/plain"), name="robots_file")
]
nginx
: stackoverflow.com/a/3746344/781695 , Perapache
: serverfault.com/a/213455/84120