关闭Django开发服务器中静态文件的缓存 [英] Turn off caching of static files in Django development server

查看:802
本文介绍了关闭Django开发服务器中静态文件的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以轻松地关闭Django开发服务器中静态文件的缓存?

我正在启动服务器标准命令:

I'm starting the server with the standard command:

$ python manage.py runserver

我已经将 settings.py 配置为从 / static 我的Django项目目录。我还有一个中间件类,它将 Cache-Control 头设置为 must-revalidate,no-cache 开发,但这似乎只会影响不在我的 / static 目录中的URL。

I've got settings.py configured to serve up static files from the /static directory of my Django project. I've also got a middleware class that sets the Cache-Control header to must-revalidate, no-cache for development, but that only seems to affect URLs that are not in my /static directory.

推荐答案

假设你使用 django.views.static.serve ,它看起来不像它 - 但是编写自己的视图,只是调用 django.views.static.serve ,添加Cache-Control标题应该很简单。

Assuming you're using django.views.static.serve, it doesn't look like it - but writing your own view that just calls django.views.static.serve, adding the Cache-Control header should be rather easy.

这篇关于关闭Django开发服务器中静态文件的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆