小编Joe*_*ark的帖子

AppEngine上的自定义django模板标签问题

所以我在这上面撞墙.我觉得我已经解释了我发现的文档和示例,但这似乎不会消失.

这是标签代码:

from google.appengine.ext import webapp

register = webapp.template.create_template_register()

def test_tag():
    return "TEST!"

register.simple_tag(test_tag)
Run Code Online (Sandbox Code Playgroud)

这是主要代码:

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, template

webapp.template.register_template_library('my_tags')

class MainHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write(template.render("test.html", {}))

def main():
    application = webapp.WSGIApplication([('/', MainHandler)], debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

这是模板:

{% load my_tags %}
<html>{% test_tag %}></html>
Run Code Online (Sandbox Code Playgroud)

这是错误:

  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django/django/template/defaulttags.py", line 750, in load
    raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e)
TemplateSyntaxError: 'my_tags' is not a valid tag library: …
Run Code Online (Sandbox Code Playgroud)

django google-app-engine templates

6
推荐指数
1
解决办法
1005
查看次数

标签 统计

django ×1

google-app-engine ×1

templates ×1