投稿    登录
  《Python3网络爬虫开发实战》赠书活动正在进行中!详情请戳赠书活动!欢迎参与!非常感谢!

Flask 静态文件缓存问题

Python 仙宇 7183浏览 118评论

大家好,今天才发现很多学习Flask的小伙伴都有这么一个问题,清理缓存好麻烦啊,今天就教大家怎么解决。

大家在使用Flask静态文件的时候,每次更新,发现CSS或是Js或者其他的文件不会更新。

这是因为浏览器的缓存问题。

普遍大家是这几步解决办法。

  • 清理浏览器缓存
  • 设置浏览器不缓存
  • 也有以下这么写的

如果是我,我不会这么做,效率很低。

这是  Flask的 config 的源码,里面可以看到,有设置缓存最大时间

SEND_FILE_MAX_AGE_DEFAULT 可以看到,它是一个 temedelta 的值

我们去更改配置。

第2行: 我们引入了datetimetimedelta对象

第6行: 我们配置缓存最大时间

 

这样就解决了缓存问题,不用去写多余的代码,不用去清理浏览器的缓存。

一定要学着去看官方文档和框架的源代码!!

有什么问题请联系

微信二维码

转载请注明:静觅 » Flask 静态文件缓存问题

喜欢 (71)or分享 (0)

我的个人微信公众号,联系我请直接在公众号留言即可~

扫码或搜索:进击的Coder

进击的Coder

微信公众号 扫一扫关注

想结交更多的朋友吗?

来进击的Coder瞧瞧吧

进击的Coder

QQ群号 99350970 立即加入

进击的Coder灌水太多?

这里是纯粹的技术领地

激进的Coder

QQ群号 627725766 立即加入

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请狠狠点击下面的

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(118)个小伙伴在吐槽
  1. below youll obtain the link to some web-sites that we feel you should visit
    Sexy chat2019-01-16 17:03 (1分钟前)回复
  2. one of our guests recently proposed the following website
    Hot webcam2019-01-16 12:40 (4小时前)回复
  3. usually posts some quite fascinating stuff like this. If youre new to this site
    Tory Burch2019-01-16 07:49 (9小时前)回复
  4. check beneath, are some entirely unrelated sites to ours, on the other hand, they may be most trustworthy sources that we use
    gucci handbags2019-01-16 07:07 (10小时前)回复
  5. Every after inside a though we decide on blogs that we read. Listed below would be the most current web-sites that we select
    lieve testo2019-01-15 10:53 (1天前)回复
  6. although internet sites we backlink to below are considerably not associated to ours, we feel they may be in fact really worth a go as a result of, so have a look
  7. below you will locate the link to some web pages that we assume you'll want to visit
    sexy Melody webcam2019-01-15 03:44 (2天前)回复
  8. check below, are some entirely unrelated web-sites to ours, nonetheless, they're most trustworthy sources that we use
    sexy Latina duo2019-01-14 23:58 (2天前)回复
  9. one of our visitors recently proposed the following website
    sexy gaming Chat2019-01-14 23:24 (2天前)回复
  10. check beneath, are some absolutely unrelated internet sites to ours, having said that, they are most trustworthy sources that we use
    attacco di panico2019-01-14 11:00 (2天前)回复
  11. always a major fan of linking to bloggers that I enjoy but do not get quite a bit of link appreciate from
  12. Sites of interest we have a link to
    Live casino singapore2019-01-13 09:37 (3天前)回复
  13. Wonderful story, reckoned we could combine several unrelated information, nonetheless truly really worth taking a search, whoa did a single learn about Mid East has got much more problerms at the same time
    Sexcams2019-01-12 18:26 (4天前)回复
1 6 7 8