2012-07-08 27 views
2

每當有在我的App Engine項目的繼承Jinja2的模板錯誤,我得到一個回溯的僅指定導致繼承,而不是導致錯誤的行的行。如何使用App Engine在Jinja2中獲得繼承模板的特定回溯?

例如,我創建了一個虛擬的項目有兩個模板,page.htmlbase.html。從base.htmlbase.htmlpage.html繼承具有被設計爲引起錯誤的行。而不是base.html報告錯誤,應用程序引擎/神社會給我這個回溯:

Traceback (most recent call last): 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 1536, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 1530, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/home/kkinder/Projects/JinjaTestProject/main.py", line 11, in get 
    self.response.out.write(self.jinja2.render_template('page.html')) 
    File "/home/kkinder/Software/google_appengine/lib/webapp2/webapp2_extras/jinja2.py", line 158, in render_template 
    return self.environment.get_template(_filename).render(**context) 
    File "/home/kkinder/Software/google_appengine/lib/jinja2/jinja2/environment.py", line 894, in render 
    return self.environment.handle_exception(exc_info, True) 
    File "templates/page.html", line 1, in top-level template code 
    {% extends 'base.html' %} 
UndefinedError: 'doesnotexist' is undefined 

main.py:

import webapp2 
from webapp2_extras import jinja2 

class MainHandler(webapp2.RequestHandler): 
    @webapp2.cached_property 
    def jinja2(self): 
     return jinja2.get_jinja2(app=self.app) 

    def get(self): 
     self.response.out.write(self.jinja2.render_template('page.html')) 

app = webapp2.WSGIApplication([('/', MainHandler)], 
          debug=True) 

page.html中:

{% extends 'base.html' %} 
{% block content %} 
    Stuff 
{% endblock %} 

base.html文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
</head> 
<body> 
<h1>{{ doesnotexist.foo }}</h1> 
    {% block content %}{% endblock %} 
</body> 
</html> 
+0

我在這裏發佈了一個相關的問題:[在Google App Engine中調試Jinja2](http://stackoverflow.com/questions/3086091/debug-jinja2-in-google -app發動機) – 2014-04-01 00:44:30

回答