django/taggit - 不可哈希类型:'list'
我正在使用 django-taggit (请参阅此处)。这就是我所拥有的:
forms.py
from taggit.forms import *
class MyForm(forms.Form):
title = forms.CharField()
my_tags = TagField(max_length=800, widget=forms.TextInput(attrs={'class':'myTags'}))
views.py
if 'submit_button' in request.POST:
form = MyForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
f_title = cd['title']
f_my_tags = cd['my_tags']
p = MyData.objects.create(title=f_title)
p.tags.add(f_my_tags)
p.save()
mytemplate.html
{{ form.my_tags.errors }}
{{ form.my_tags }}
不知道为什么当我使用 p.tags.add(f_my_tags)
unhashable type: 'list' > 在我看来.py。有什么想法吗?谢谢你!
I'm using django-taggit (see here). This is what I have:
forms.py
from taggit.forms import *
class MyForm(forms.Form):
title = forms.CharField()
my_tags = TagField(max_length=800, widget=forms.TextInput(attrs={'class':'myTags'}))
views.py
if 'submit_button' in request.POST:
form = MyForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
f_title = cd['title']
f_my_tags = cd['my_tags']
p = MyData.objects.create(title=f_title)
p.tags.add(f_my_tags)
p.save()
mytemplate.html
{{ form.my_tags.errors }}
{{ form.my_tags }}
Not sure why I get unhashable type: 'list'
when I use p.tags.add(f_my_tags)
in my views.py. Any ideas? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要单独添加标签:
这相当于:
或将它们作为位置参数传递给tags.add:
这相当于:
p.tags.add(cd['my_tags'][0], cd['my_tags][1]... )
You need to either add tags individually:
this is equivalent to:
or pass them as positional arguments to tags.add:
this being equivalent to:
p.tags.add(cd['my_tags'][0], cd['my_tags][1]... )