gae_mini_profiler {% profiler_includes %} gives Invalid block tag: 'profiler_includes'

那年仲夏 提交于 2019-12-13 13:23:17

问题


I am attempting to install gae_mini_profiler in my django-nonrel app

I placed the {% profiler_includes %} tag at the bottom of my base.html

It results in a

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

I placed

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

at the bottom of djangoppengine/main/__init__.py

I followed all the other instructions at https://github.com/kamens/gae_mini_profiler#start

What am I doing wrong?


回答1:


I solved this by changing gae_mini_profiler/templatetags.py to be a true template tag library.

To do this create a package called templatetags, and then move(and rename) the templatetags.py module to profiler_tags.py.

Inside of profiler_tags.py make the following changes:

Change:

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

To:

from django.template import Library
register = Library()

Change:

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

To:

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

In your settings file add gae_mini_profiler to your list of installed apps.


Remove all references to

template.register_template_library('gae_mini_profiler.templatetags')

In your templates whereever you had {% profiler_includes %} you then need to add a load block

 {% load profiler_tags %}

I think that is all of the changes, but need to go check my git log.




回答2:


Are you using the new Python 2.7 runtime for GAE? If so, the django template setup is slightly different and gae_mini_profiler hasn't been upgraded yet (anyone is welcome to submit this fix, haven't gotten to it yet).

It should be easy to work around as the only thing you need to do is find a way to render the HTML string returned by gae_mini_profiler.templatetags.profiler_includes() anywhere in your page. There are a number of methods of accomplishing this if the built-in template tag isn't working as-is. You could simply call the function in your base request handler and pass the resulting html into your base template if absolutely necessary (although this is admittedly a gross hack).

We'll hopefully have Python 2.7 working w/ gae_mini_profiler shortly. If you're not on Python 2.7, I'm not sure what the issue is as I'd expect the current code to work...



来源:https://stackoverflow.com/questions/8337262/gae-mini-profiler-profiler-includes-gives-invalid-block-tag-profiler-inc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!