Django-taggit-templatetags2 属性错误
Django-taggit-templatetags2 Attribute Error
我需要帮助将标签段用作包含该标签的所有帖子的 link。使用 Django-taggit-templatetags2.
'function'对象没有属性'filter'
tags.html
<h2>Tags</h2>
{% get_taglist as tags %}
{% for tag in tags %}
<h4><a href="{{tag}}">{{tag}} x{{tag.num_times}}</a></h4>
{% endfor %}
urls.py
url(r'^blog/tags/(?P<slug>[a-z0-9]+)/$', views.TagDetailView.as_view(), name = 'tag'),
views.py
class TagDetailView(DetailView):
template_name = 'home/tag.html'
context_object_name = 'tag'
def get_queryset(self):
return Post.objects.all
回溯:
内部文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/exception.py”
39.响应=get_response(请求)
_get_response 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py”
187. 响应 = self.process_exception_by_middleware(e, 请求)
_get_response 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py”
185.响应=wrapped_callback(请求,*callback_args,**callback_kwargs)
文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py”在视图中
68. return self.dispatch(请求,*args,**kwargs)
调度文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py”
88. return 处理程序(请求,*args,**kwargs)
获取文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/detail.py”
115.self.object=self.get_object()
get_object 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/detail.py”
43. queryset = queryset.filter(**{slug_field: 鼻涕虫})
异常类型:/blog/tags/mods/ 处的 AttributeError
异常值:'function' 对象没有属性 'filter'
您忘记了 views.py
中的一对括号:
class TagDetailView(DetailView):
template_name = 'home/tag.html'
context_object_name = 'tag'
def get_queryset(self):
return Post.objects.all()
我需要帮助将标签段用作包含该标签的所有帖子的 link。使用 Django-taggit-templatetags2.
'function'对象没有属性'filter'
tags.html
<h2>Tags</h2>
{% get_taglist as tags %}
{% for tag in tags %}
<h4><a href="{{tag}}">{{tag}} x{{tag.num_times}}</a></h4>
{% endfor %}
urls.py
url(r'^blog/tags/(?P<slug>[a-z0-9]+)/$', views.TagDetailView.as_view(), name = 'tag'),
views.py
class TagDetailView(DetailView):
template_name = 'home/tag.html'
context_object_name = 'tag'
def get_queryset(self):
return Post.objects.all
回溯:
内部文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/exception.py” 39.响应=get_response(请求)
_get_response 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py” 187. 响应 = self.process_exception_by_middleware(e, 请求)
_get_response 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py” 185.响应=wrapped_callback(请求,*callback_args,**callback_kwargs)
文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py”在视图中 68. return self.dispatch(请求,*args,**kwargs)
调度文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py” 88. return 处理程序(请求,*args,**kwargs)
获取文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/detail.py” 115.self.object=self.get_object()
get_object 中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/detail.py” 43. queryset = queryset.filter(**{slug_field: 鼻涕虫})
异常类型:/blog/tags/mods/ 处的 AttributeError 异常值:'function' 对象没有属性 'filter'
您忘记了 views.py
中的一对括号:
class TagDetailView(DetailView):
template_name = 'home/tag.html'
context_object_name = 'tag'
def get_queryset(self):
return Post.objects.all()