Django Tagging - 分离标签的问题
我在 django 标记方面遇到了麻烦 - 按由多个单词组成的标记进行过滤不起作用。 模型
class MyWidget(models.Model):
"""Widget for tagging. It's damn bugged, so it need try except statement
for be able to import in shell and work in general. Otherwise it's raiseing
exception."""
name = models.CharField(max_length = 50)
try:
tagging.register(MyWidget)
except tagging.AlreadyRegistered:
pass
视图
class PostsByTags(ListView):
"""View returns news filtered by tag."""
template_name = 'news.djhtml'
contect_object_name = 'news_list'
def get_queryset(self):
tags = unquote(self.kwargs['tag'])
return TaggedItem.objects.get_by_model(News(), tags)
url
url(r'^news/(?P<tag>[\w\s]*)/$', views.PostsByTags.as_view(),
name = 'tagged_news'),
如果 url 看起来像这样
/news/separated%20tag/
视图类返回空列表。到底是什么原因呢?我该如何修复它?
I have got trouble with django tagging - filtering by tags consisting of several words does not work.
models
class MyWidget(models.Model):
"""Widget for tagging. It's damn bugged, so it need try except statement
for be able to import in shell and work in general. Otherwise it's raiseing
exception."""
name = models.CharField(max_length = 50)
try:
tagging.register(MyWidget)
except tagging.AlreadyRegistered:
pass
views
class PostsByTags(ListView):
"""View returns news filtered by tag."""
template_name = 'news.djhtml'
contect_object_name = 'news_list'
def get_queryset(self):
tags = unquote(self.kwargs['tag'])
return TaggedItem.objects.get_by_model(News(), tags)
urls
url(r'^news/(?P<tag>[\w\s]*)/
If url looking something like that
/news/separated%20tag/
the view class returns empty list. What the cause? How can I fix it?
, views.PostsByTags.as_view(),
name = 'tagged_news'),
If url looking something like that
/news/separated%20tag/
the view class returns empty list. What the cause? How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为查询标签被分成两部分(在 tagging.utils.parse_tag_input 中)。
get_by_model 也可以采用标签项而不是字符串,因此请尝试类似的操作。
I thinks the query tag is being split into two (in tagging.utils.parse_tag_input).
get_by_model can also take a Tag item rather then a string, so try something like.
格式化你的网址怎么样:
What about formatting your url: