How to set static file in django with templateview

Sometimes I got confused whether to set my static file with nginx or just inside the Django.

This is how I do it inside urls.py in django app directory.

from django.views.generic import TemplateView

urlpatterns = {
    ....
    url(r'^static\.txt$', TemplateView.as_view(template_name='files/static.txt', content_type='text/plain')),
    ....
}

and navigate to https://myurl.com/static.txt

Leave a Comment