gpt4 book ai didi

python Bottle网络服务器缓存html文件

转载 作者:行者123 更新时间:2023-11-30 22:16:59 26 4
gpt4 key购买 nike

我正在 python 中使用 Bottle 网络服务器。当我调试时,我想对伪html模板文件进行更改,然后重新加载页面以在浏览器中查看它。看来 Bottle 缓存了模板文件,我无法从新修改的模板中加载它们。

这是我的情况:

第一种方法

  1. 运行网络服务器,拉起main.tpl.html
  2. 更改文件名secondary.tpl.html 到 secondary2.tpl.html
  3. 打开 secondary.tpl.html(不再存在)
  4. 得到 404 错误,即。一切顺利

第二种方法

  1. 运行网络服务器,拉起main.tpl.html
  2. 打开 secondary.tpl.html,工作正常
  3. 将 secondary.tpl.html 的文件名更改为 secondary2.tpl.html
  4. 重新加载 secondary.tpl.html(不再存在)
  5. 获取不再应该存在的原始 secondary.tpl.html 网页

我强制浏览器再次请求该文件(不使用它自己的缓存),并且通过 python 调试器(PyCharm),我可以看到 Bottle Web 服务器至少假装执行以下操作它应该用模板文件做的所有事情。

最佳答案

来自http://bottlepy.org/docs/dev/stpl.html#bottle.SimpleTemplate

Just keep in mind that compiling and rendering templates are two different actions, even if the template() helper hides this fact. Templates are usually compiled only once and cached internally, but rendered many times with different keyword arguments.

但是http://bottlepy.org/docs/dev/tutorial.html#templates状态:

Caching

Templates are cached in memory after compilation. Modifications made to the template files will have no affect until you clear the template cache. Call bottle.TEMPLATES.clear() to do so. Caching is disabled in debug mode.

您可以在http://bottlepy.org/docs/dev/tutorial.html#debug-mode找到它

bottle.debug(True)

In this mode, Bottle is much more verbose and provides helpful debugging information whenever an error occurs. It also disables some optimisations that might get in your way and adds some checks that warn you about possible misconfiguration.

Here is an incomplete list of things that change in debug mode:

The default error page shows a traceback.
Templates are not cached.
Plugins are applied immediately.

如果这仍然没有帮助,请进行一些浏览 https://github.com/bottlepy/bottle/blob/master/bottle.py#L3937

class SimpleTemplate(BaseTemplate):
def prepare(self,
escape_func=html_escape,
noescape=False,
syntax=None, **ka):
self.cache = {}
...

这似乎清除了缓存。

关于python Bottle网络服务器缓存html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49804021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com