【问题标题】:Bottle framework caches my template even in debug mode即使在调试模式下,Bottle 框架也会缓存我的模板
【发布时间】:2015-06-27 20:55:51
【问题描述】:

这里有一个类似的问题,但答案已经超过 2 年了,我无法让它发挥作用。如果我遗漏了什么 - 请告诉我。
Bottle.py caching templates despite being in debug mode

每当浏览器指向 0.0.0.0:8080/16boxes 时,我都需要阻止缓存。 Bottle 文档说当处于调试模式时,缓存被禁用,但不幸的是我不是这种情况。

这是我的 hello.py 代码:

@route('/16boxes')
def send_static():
    response.set_header('Cache-control', 'no-cache, must-revalidate')
    return template (resource_path('16boxes.html'), globalVar0 = globalVar0)
run(host='0.0.0.0', port=8080, debug=True)

我打开终端并运行:python hello.py

当我在 Mac/Chrome 上运行它时它不会缓存 - 但当我使用 Windows 和 Internet Explorer 时 - 它使用缓存版本。我怎样才能防止这种情况发生?

在我的 16boxes.html 中,我什至有以下内容:

<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Pragma" content="no-cache">

【问题讨论】:

  • 更改文件时应用程序是否会重新加载?
  • 不,只有当我清除浏览器中的缓存时。

标签: python html caching server bottle


【解决方案1】:

您的问题是由于浏览器缓存导致页面加载时您的 JavaScript onload 事件不会触发,jQuery's ready 事件就是为此类问题创建的。

【讨论】:

  • 当我输入“app = bottle.app()”时,我得到“NameError: name 'bottle' is not defined.
  • 在该行之前添加import bottle
  • 这很有趣,因为我总是有“从瓶子进口......东西”所以我认为它是进口的,但我猜不是!添加导入瓶允许 bottle.app() 工作 - 但当我运行它时,它仍在加载我的 HTML 文件的缓存版本。
  • 问题是 - 当我的 HTML 页面加载时,我的 body 标签上有一个 javascript 函数 - 我需要这个 javascript 函数来触发一切正常工作.因此,似乎在加载缓存版本时,该功能永远不会启动。
  • 是的!使用 Jquery 准备好而不是加载是解决方法!编辑你的答案,我会接受!
猜你喜欢
  • 1970-01-01
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-22
  • 1970-01-01
  • 1970-01-01
  • 2011-10-24
相关资源
最近更新 更多