相关疑难解决方法(0)

Django无法加载模板标记

templatetags在我的应用程序中创建了一个文件夹,在一个名为的文件中posts.py,我编写了以下代码;

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) 
Run Code Online (Sandbox Code Playgroud)

现在,我尝试在模板中加载此模板标记;

{% load get_all_posts %}
Run Code Online (Sandbox Code Playgroud)

但这给了我错误, '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

3
推荐指数
1
解决办法
4207
查看次数

标签 统计

django ×1

django-templates ×1

django-views ×1