背景:Google App Engine SDK 1.8.4, Python2.7+Django 1.2+Webapp2
为本地 dev_appserver运行的,主要信息如下:
#tags/filter.py 文件关键内容
from django import template
register = template.Library()
@
register.tag("upper")
def do_upper(parser, token):
nodelist = parser.parse(('endupper',))
parser.delete_first_token()
return UpperNode(nodelist)
class UpperNode(template.Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context):
output = self.nodelist.render(context)
return output.upper()
-------------------------------------------------------------------------------------
#test.py webapp2的app已注册此模板标签,
import webapp2
from google.appengine.ext.webapp import template
template.register_template_library('tags.filter')
class BaseHandler(webapp2.RequestHandler):
#... .... 根据模板显示网页... ...self.response.write(template.render(path, template_args))
... 略 ...
template.register_template_library('tags.filter')
app = webapp2.WSGIApplication([
('/test, BaseHandler),
], debug=False)
-------------------------------------------------------------------------------------
html模板文件主要内容为
{% upper %}<p>This is a test!</p>{% endupper %}
运行后查看源文件此页面对应行显示为
<tags.filter.UpperNode object at 0x0486A7F0>
而不是 “<P>THIS IS A TEST!</P> ”,请各位看下是什么问题呢?