Turn off caching of static files in Django development server

后端 未结 9 2214
灰色年华
灰色年华 2020-11-30 04:52

Is there an easy way to turn off caching of static files in Django\'s development server?

I\'m starting the server with the standard command:

<
9条回答
  •  执念已碎
    2020-11-30 05:21

    My very simple solution:

    from django.contrib.staticfiles.views import serve
    from django.views.decorators.cache import never_cache
    
    static_view = never_cache(serve)
    urlpatterns += static_view(settings.MEDIA_URL,
                               document_root=settings.MEDIA_ROOT)
    

提交回复
热议问题