Webapp2自定义标签 [英] Webapp2 custom tags

查看:143
本文介绍了Webapp2自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从webapp1迁移到webapp2和从python 2.5迁移到python2.7
我有一些自定义标签,用于

  webapp.template.register_template_library('common.templatetags')

注册:

  from google.appengine.ext.webapp导入模板
register = template.create_template_register()

code>

以及相应的装饰器和其他一切正常工作现在我需要

使用webapp2,它没有template.register .....



我试过这样做: http://www.john-smith.me/Tag/webapp2
但它无效



谢谢

解决方案

使用add_to_builtins()解决问题

  from django.template.loader import add_to_builtins 

add_to_builtins('myapp.templatetags.mytagsli b')


I am migrating from webapp1 to webapp2 and from python 2.5 to python2.7 I had some custom tags I used with

webapp.template.register_template_library('common.templatetags')

and registered with:

from google.appengine.ext.webapp import template
register = template.create_template_register()

and the corresponding decorator and everything else worked fine

now I need to use webapp2 which does not have template.register.....

I tried doing it this way : http://www.john-smith.me/Tag/webapp2 but it didn't work

thanks

解决方案

solved by using add_to_builtins()

from django.template.loader import add_to_builtins

add_to_builtins('myapp.templatetags.mytagslib')

这篇关于Webapp2自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆