Bottle.py缓存模板,尽管处于调试模式 [英] Bottle.py caching templates despite being in debug mode

查看:136
本文介绍了Bottle.py缓存模板,尽管处于调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在GAE上构建了我的第一个Bottle.py应用程序。它的工作原理除了当我更改模板时,我必须重新启动dev服务器才能看到更改。该文档说模板缓存应该在bottle.debug(True)时被禁用,并且您也可以调用bottle.TEMPLTE.clear(),但这两者都不起作用。我也尝试设置运行(reloader = True),但这会导致错误。我究竟做错了什么? bottle.debug()是否适用于GAE上的其他人?

 导入瓶
bottle.debug(True)
bottle.TEMPLATES.clear()

@ bottle.route('/')
def index(name ='World'):
return bottle.template( 'main')

bottle.run(server ='gae')






更新:
我并没有使用bottle.run(server ='gae'),而是自己和现在包含了标准main

  def main():
app = bottle.default_app()
util.run_wsgi_app (app)

if __name__ ==__main__:
main()


$ b $ p $ app = bottle .app()



然后调用 dev_appserver.py ,它读取 app.yaml 并从您定义的脚本导入您的应用程序,并处理GAE环境的其他所有内容ENT。

你不应该直接运行你的.py。从bottle方式运行将跳过dev_appserver中的那些句柄,包括模板缓存机制。当然,使用来自Google的 util 确实有效,但根据 uwsgi 或其他与wsgi相关的项目'文档中,脚本模块中的 app 变量是应该为上层处理提供的对象。

I just built my first Bottle.py app on GAE. It's working except that when I change the templates I have to restart the dev server to see the changes. The docs say that template caching is supposed to be disabled when bottle.debug(True), and that you can call bottle.TEMPLTE.clear() as well, but neither of those work. I also tried setting run(reloader=True) but that causes an error. What am I doing wrong? Does bottle.debug() work for anyone else on GAE?

import bottle
bottle.debug(True)
bottle.TEMPLATES.clear()

@bottle.route('/')
def index(name='World'):
    return bottle.template('main')

bottle.run(server='gae')


Update: Instead of using bottle.run(server='gae'), I included the standard main() function myself and now it works.

def main():
  app = bottle.default_app()
  util.run_wsgi_app(app)

if __name__ == "__main__":
  main()

解决方案

The standard method introduced by Bottle/GAE doc is:

app = bottle.app()

then invoke dev_appserver.py, it reads app.yaml and import your app from the script you defined, and handle everything else for a GAE environment.

You shouldn't run your .py directly. Running from the bottle way will skip those handles from dev_appserver, including the template cached mechanism. Of course, using the util from Google does trick way and works, but according to uwsgi or other wsgi related projects' documents, the app variable in the script module is the object should be offered for the upper handling.

这篇关于Bottle.py缓存模板,尽管处于调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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