gae_mini_profiler {% profiler_includes %} gives In

2019-06-28 06:38发布

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?

2条回答
Animai°情兽
2楼-- · 2019-06-28 06:58

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.

查看更多
再贱就再见
3楼-- · 2019-06-28 07:12

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...

查看更多
登录 后发表回答