Jed Christiansen Jed Christiansen - 6 months ago 24
Python Question

Problems configuring gae_mini_profiler correctly

I'm having problems getting working correctly in my app.

I've followed the instructions carefully, and this is my app (with needless stuff stripped out.)

import webapp2
from webapp2_extras import jinja2
import appengine_config
import handlers
import gae_mini_profiler.profiler

class MainHandler(handlers.BaseRequestHandler):
def get(self):
user = separate_file.get_user_and_logins(self)
templateid = 'home.html'
context = {
'user': user,
self.render(templateid, context)

app_config = {
'webapp2_extras.jinja2.default_config': {
'globals': {
'profiler_includes': gae_mini_profiler.templatetags.profiler_includes,

app = webapp2.WSGIApplication([
('/', MainHandler)], config=app_config, debug=True)
app = gae_mini_profiler.profiler.ProfilerWSGIMiddleware(app)

I'm getting this error:

ERROR 2015-05-21 20:23:25,460]
Traceback (most recent call last):
File "/Users/jedc/google-cloud-sdk/platform/", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/jedc/google-cloud-sdk/platform/", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/jedc/google-cloud-sdk/platform/", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/jedc/mypathtomyapp/", line 33, in <module>
'profiler_includes': gae_mini_profiler.templatetags.profiler_includes,
AttributeError: 'module' object has no attribute 'templatetags'

Is this perhaps because I'm using webapp2 instead of webapp for my main application? Or should I be importing gae_mini_profiler differently? I can't figure it out.


After specifically importing gae_mini_profiler.templatetags, I've now got a new error.

File "/Users/jedc/Dropbox (Personal)/code/seeddb-devbranch/seeddbapp/", line 22, in get
self.render(templateid, context)
File "/Users/jedc/Dropbox (Personal)/code/seeddb-devbranch/seeddbapp/", line 64, in render
self.response.write(self.jinja2.render_template(template_name, **values))
File "/Users/jedc/google-cloud-sdk/platform/", line 158, in render_template
return self.environment.get_template(_filename).render(**context)
File "/Users/jedc/google-cloud-sdk/platform/", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "templates/base.html", line 118, in template
{% profiler_includes %}
TemplateSyntaxError: Encountered unknown tag 'profiler_includes'.

and the end of base.html has:

{% profiler_includes %}

Now if I change:

{% profiler_includes %}


{{ profiler_includes }}

it clears the error but doesn't actually seem to trigger the function.

I am not a Jinja2 expert, but am I specifying something incorrectly when I define the function in the webapp2_extras.jinja2.default_config section?


You're missing an import statement. You should explicitly also import gae_mini_profiler.templatetags since you're using it.

import gae_mini_profiler.templatetags