我需要帮助使用标签段作为包含该标签的所有帖子的链接。使用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. response = get_response(request)
_get_response中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py” 187. response = self.process_exception_by_middleware(e,request)
_get_response中的文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/core/handlers/base.py” 185. response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py”在视图中 68.返回self.dispatch(request,* args,** kwargs)
发送文件“/home/vinyasa/web_dev/practice/venv/lib/python3.5/site-packages/django/views/generic/base.py” 88.返回处理程序(request,* 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:slug})
异常类型:/ blog / tags / mods /中的AttributeError 异常值:'function'对象没有属性'filter'
答案 0 :(得分:0)
您忘记了views.py
中的一对括号:
class TagDetailView(DetailView):
template_name = 'home/tag.html'
context_object_name = 'tag'
def get_queryset(self):
return Post.objects.all()