from django.views.generic import TemplateView urlpatterns = [ url(r‘^test/‘,TemplateView.as_view(template_name=‘test.txt‘)), url(r‘^test.txt$‘, TemplateView.as_view(template_name="test.txt", content_type="text/plain"), name="test") ]
访问方式:
http://127.0.0.1/test/
http://127.0.0.1/test.txt
python django url直接访问txt文件。urls.py路由直接指向txt文件
原文:https://www.cnblogs.com/fanhua999/p/11361072.html