正确配置gae_mini_profiler时出现问题

时间:2015-05-21 20:40:55

标签: python google-app-engine jinja2

我在使用https://github.com/Khan/gae_mini_profiler在我的应用中正常工作时遇到了问题。

我已经仔细按照说明操作,这是我的应用程序(不必要的东西被剥离了。)

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

我收到了这个错误:

  File "/Users/jedc/Dropbox (Personal)/code/seeddb-devbranch/seeddbapp/main.py", line 22, in get
self.render(templateid, context)
  File "/Users/jedc/Dropbox (Personal)/code/seeddb-devbranch/seeddbapp/handlers.py", line 64, in render
self.response.write(self.jinja2.render_template(template_name, **values))
  File "/Users/jedc/google-cloud-sdk/platform/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.1/webapp2_extras/jinja2.py", line 158, in render_template
return self.environment.get_template(_filename).render(**context)
  File "/Users/jedc/google-cloud-sdk/platform/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/jinja2-2.6/jinja2/environment.py", 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'.

这可能是因为我在主应用程序中使用webapp2而不是webapp吗?或者我应该以不同方式导入gae_mini_profiler?我无法理解。

更新

在专门导入gae_mini_profiler.templatetags之后,我现在遇到了一个新错误。

  </div>
  {% profiler_includes %}
  </body>
</html>

并且base.html的结尾有:

{% profiler_includes %}

现在,如果我改变:

{{ profiler_includes }}

为:

<!DOCTYPE html>

<html lang="en">

<head>
        <meta charset="utf-8"/>
        <title>jeKnowledge's Interative Website</title>
        <link href="main.css" rel="stylesheet">

        <!-- IMAGE MAPSTER-->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
        <script src="jquery.imagemapster" type="text/javascript"></script>
        <script src="app.js" type="text/javascript"></script>


</head>

<body>
<div>

        <map name="webjek">
            <area href = "#" shape="poly" coords="0, 474, 12, 464, 31, 462, 46, 465, 64, 477, 74, 499, 81, 518, 72, 533, 71, 544, 73, 552, 91, 551, 103, 556, 116, 560, 131, 580, 144, 603, 152, 624, 162, 644, 158, 652, 162, 650, 174, 667, 245, 667, 246, 615, 253, 603, 264, 592, 275, 589, 286, 550, 318, 526, 349, 508, 344, 500, 343, 492, 347, 483, 351, 478, 357, 448, 375, 428, 403, 430, 421, 437, 431, 455, 429, 480, 424, 498, 421, 515, 443, 514, 469, 533, 481, 559, 497, 591, 493, 592, 508, 614, 520, 644, 540, 641, 530, 665, 538, 667, 0, 666" alt="inovacao" title="Departamento de Inovação"/>
            <area href="#" shape="poly" class="{fillColor:'00ff00'}"coords="1064, 668, 1110, 481, 1348, 550, 1346, 667" alt="sjmeeting" title="Summer Jade Meeting" />
            <area href="#" shape="poly" coords="868, 456, 942, 191, 1128, 212, 1040, 517, 865, 464" alt="rec" title="Recrutamento" />
            <area href="#" shape="poly" coords="458, 105, 458, 155, 491, 154, 491, 166, 518, 168, 519, 118, 490, 119, 489, 105" alt="shifth" title="ShiftHappens" />

        </map>

    </div>


    <div id="background"><img class="mapper" id="myimage" src="C:\Users\Pedro\Desktop\projeto jeKnowledge\image.jpg" alt="" usemap="#webjek"></div>


</body>

</html>

它清除了错误,但实际上似乎没有触发该功能。

不是 Jinja2专家,但是当我在webapp2_extras.jinja2.default_config部分定义该函数时,我是否指定了错误的内容?

2 个答案:

答案 0 :(得分:2)

你错过了一个import语句。您应该明确地导入gae_mini_profiler.templatetags,因为您正在使用它。

import gae_mini_profiler.templatetags

答案 1 :(得分:1)

关于更新

这:{{ profiler_includes() | safe }}

而不是:{% profiler_includes %}

是我最终能够在python2.7 / jinja2中使用gae_mini_profiler包含的...