【发布时间】:2012-01-26 07:28:02
【问题描述】:
我在我的应用程序和一个名为posts.py 的文件中创建了一个templatetags 文件夹,我编写了以下代码;
from django.template import Library, Node
from advancedviews.models import Post
register = Library()
class AllPost(Node):
def render(self,context):
context['all_posts'] = Post.objects.all()
return ''
def get_all_posts(parser,token):
return AllPost()
get_all_posts = register.tag(get_all_posts)
现在,我尝试在我的模板中加载这个模板标签;
{% load get_all_posts %}
但这给了我错误,'get_all_posts' is not a valid tag library: Template library get_all_posts not found, tried django.templatetags.get_all_posts,django.contrib.admin.templatetags.get_all_posts
这个模板有什么错误或者我在这里遗漏了什么。
【问题讨论】:
标签: django django-templates django-views