【问题标题】:gae_mini_profiler {% profiler_includes %} gives Invalid block tag: 'profiler_includes'gae_mini_profiler {% profiler_includes %} 给出了无效的块标签:'profiler_includes'
【发布时间】:2012-01-10 08:34:04
【问题描述】:

我正在尝试在我的 django-nonrel 应用中安装 gae_mini_profiler

我将{% profiler_includes %} 标签放在了base.html 的底部

结果是

Exception Type: TemplateSyntaxError
Exception Value: Invalid block tag: 'profiler_includes'

我放了

from gae_mini_profiler import profiler
application = profiler.ProfilerWSGIMiddleware(application)

djangoppengine/main/__init__.py底部

我遵循https://github.com/kamens/gae_mini_profiler#start 的所有其他说明

我做错了什么?

【问题讨论】:

    标签: django google-app-engine profiling django-nonrel


    【解决方案1】:

    您是否正在为 GAE 使用新的 Python 2.7 运行时?如果是这样,则 django 模板设置略有不同,并且 gae_mini_profiler 尚未升级(欢迎任何人提交此修复,尚未完成)。

    这应该很容易解决,因为您唯一需要做的就是找到一种方法来呈现由gae_mini_profiler.templatetags.profiler_includes() 返回的 HTML 字符串在您的页面中的任何位置。如果内置模板标签不能按原样工作,有很多方法可以实现这一点。如果绝对必要,您可以简单地在基本请求处理程序中调用该函数并将生成的 html 传递到您的基本模板中(尽管这无疑是一个严重的黑客攻击)。

    我们希望不久之后 Python 2.7 就能与 gae_mini_profiler 一起工作。如果您不在 Python 2.7 上,我不确定问题是什么,因为我希望当前代码能够正常工作...

    【讨论】:

    • 您可能会在 appstats 中发现此错误,以及 code.google.com/p/googleappengine/issues/detail?id=6448
    • @DataSurfer 是的,这就是问题所在。如果你降到 2.5 一切都会好起来的,否则你可以尝试上面的快速解决方法或等到我们升级到 2.7 兼容性。
    • 等等,上面的unicode问题导致了invalid block tag错误?我之所以找到它,是因为 appstats 没有在报告中包含 url 路径。
    • 不,抱歉 -- Python 2.7 是问题所在。
    • 我最终使 templatetags.py 实际上是一个模板标签库,然后在我的应用程序列表中包含了 mini_profiler,并在我的模板中“加载”了该库。
    【解决方案2】:

    我通过将gae_mini_profiler/templatetags.py 更改为真正的模板标签库解决了这个问题。

    为此,创建一个名为 templatetags 的包,然后将 templatetags.py 模块移动(并重命名)到 profiler_tags.py。

    在 profiler_tags.py 内部进行以下更改:

    变化:

    from google.appengine.ext import webapp
    register = webapp.template.create_template_register()
    

    收件人:

    from django.template import Library
    register = Library()
    

    变化:

    path = os.path.join(os.path.dirname(__file__), "templates/includes.html")
    

    收件人:

    path = os.path.join(os.path.dirname(__file__), "../templates/includes.html")
    

    在您的设置文件中,将 gae_mini_profiler 添加到您的已安装应用列表中。


    删除所有对

    的引用
    template.register_template_library('gae_mini_profiler.templatetags')
    

    在您拥有{% profiler_includes %} 的模板中,您需要添加一个加载块

     {% load profiler_tags %}
    

    我认为这就是所有的变化,但需要去检查我的 git 日志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-20
      • 2013-10-08
      • 1970-01-01
      • 2011-07-18
      • 2016-01-26
      • 2015-02-10
      • 1970-01-01
      • 2013-09-01
      相关资源
      最近更新 更多