python bottle 网络服务器缓存 html 个文件
python bottle webserver caches html files
我在 python 中使用 bottle 网络服务器。当我调试时,我想更改伪 html 模板文件,然后重新加载页面以在浏览器中查看它。好像bottle缓存了模板文件,我无法从新修改的模板中加载它们。
这是我的情况:
第一种方法
- 运行 网络服务器,上拉main.tpl.htlml
- 更改文件名
secondary.tpl.html 到 secondary2.tpl.html
- 打开secondary.tpl.html(不再存在)
- 得到 404 错误即。一切都很好
第二种方法
- 运行 网络服务器,上拉main.tpl.htlml
- 打开 secondary.tpl.html,工作正常
- 将 secondary.tpl.html 的文件名更改为 secondary2.tpl.html
- 重新加载secondary.tpl.html(不再存在)
- 获取不再应该存在的原始secondary.tpl.html网页
我已经强制浏览器第二次请求该文件(不使用它自己的缓存),并且通过 python 调试器 (PyCharm),我可以看到 bottle 网络服务器是至少假装完成所有它应该用模板文件做的事情。
来自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 模板文件,然后重新加载页面以在浏览器中查看它。好像bottle缓存了模板文件,我无法从新修改的模板中加载它们。
这是我的情况:
第一种方法
- 运行 网络服务器,上拉main.tpl.htlml
- 更改文件名 secondary.tpl.html 到 secondary2.tpl.html
- 打开secondary.tpl.html(不再存在)
- 得到 404 错误即。一切都很好
第二种方法
- 运行 网络服务器,上拉main.tpl.htlml
- 打开 secondary.tpl.html,工作正常
- 将 secondary.tpl.html 的文件名更改为 secondary2.tpl.html
- 重新加载secondary.tpl.html(不再存在)
- 获取不再应该存在的原始secondary.tpl.html网页
我已经强制浏览器第二次请求该文件(不使用它自己的缓存),并且通过 python 调试器 (PyCharm),我可以看到 bottle 网络服务器是至少假装完成所有它应该用模板文件做的事情。
来自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 = {}
...
这似乎清除了缓存。