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

标签 django google-app-engine templates

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

标签代码如下:

from google.appengine.ext import webapp

register = webapp.template.create_template_register()

def test_tag():
    return "TEST!"

register.simple_tag(test_tag)

主要代码如下:

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()

这是模板:

{% load my_tags %}
<html>{% test_tag %}></html>

这里是错误:

  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: Could not load template library from django.templatetags.my_tags, No module named my_tags

我真的很讨厌直接要求别人修复我的代码,但我似乎无法弄清楚为什么这行不通。任何提示或指示将不胜感激。

jc

最佳答案

所以事实证明,当你使用我用来注册自定义标签的方法时,你不需要使用我的示例模板顶部的加载语句。

关于django - AppEngine 上的自定义 django 模板标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4059606/

相关文章:

python - 从 docker 中的 pipfile.lock 安装时出错

python - 如何通过动态查询比较表的 2 列

python - 在django中扩展用户模型后,我无法登录

django - 将来自不同应用程序/对象的模型分组到一个管理 block 中

jquery - 在 GAE 中找不到背景图像

c++ - 如何使用特征来访问编译时 const 值?

c++ - '<' token 之前的预期模板名称

java - 如何在本地开发服务器上启用 Google Cloud Storage?

java - 如何以不同用户身份从 gwt/gae 上的 servlet 注销/登录

python - Django:奇怪的 TemplateDoesNotExist 错误