python django url直接访问txt文件。urls.py路由直接指向txt文件

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

http://127.0.0.1/test.txt

 

转载于:https://www.cnblogs.com/fanhua999/p/11361072.html

你可能感兴趣的:(python django url直接访问txt文件。urls.py路由直接指向txt文件)