Gae_mini_profiler {% profiler_includes%} gives an invalid block tag: 'profiler_includes'

I am trying to set gae_mini_profiler in my django-nonrel application

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

The result is

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

I posted

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

bottom djangoppengine/main/__init__.py

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

What am I doing wrong?

+4
source share
2 answers

I solved this by modifying gae_mini_profiler/templatetags.py as 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 profiler_tags.py, make the following changes:

Edit:

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

To:

 from django.template import Library register = Library() 

Edit:

 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 the list of installed applications.


Remove all links to

 template.register_template_library('gae_mini_profiler.templatetags') 

In your templates, when you had {% profiler_includes %} , you need to add a loading block

  {% load profiler_tags %} 

I think these are all changes, but I need to check my git log.

+2
source

Are you using the new Python 2.7 runtime for GAE? If so, the django template setting is slightly different, and gae_mini_profiler has not yet been updated (anyone can send this fix, haven't received it yet).

This should be easy to work as you only need to find a way to display the HTML string returned by gae_mini_profiler.templatetags.profiler_includes() anywhere in your page. There are several ways to accomplish this if the built-in template tag does not work as is. You can simply call the function in the base request handler and pass the resulting html to your base template if it is absolutely necessary (although this is admittedly a gross hack).

We hope that Python 2.7 will work with gae_mini_profiler soon. If you're not on Python 2.7, I'm not sure what the problem is, since I expect the current code to work ...

0
source

Source: https://habr.com/ru/post/1384048/


All Articles