我在django项目中遇到了问题。
/ contact / 1 / view' ascii'中的UnicodeEncodeError编解码器不能解码位置28中的字节0xd0:序数不在范围内(128)
回溯中的: single_contact中的views.py
'vcard_str': unicode(VCard(contact)),
和所有观点
def single_contact(request, pk):
contact = Contact.objects.get(pk = pk)
if contact.group.user != request.user.profile:
raise Http404
if request.method=="GET":
emails = Email.objects.filter(contact = contact)
hash = ''
if emails:
email = emails[0]
hash = get_hash(email.email)
addresses = Address.objects.filter(contact = contact)
if addresses:
address = addresses[0]
phones = PhoneNumber.objects.filter(contact=contact)
return render(request, 'dashboard/addressbook/single_contact.html',
RequestContext(request, {
'contact':contact, 'emails':emails, 'hash':hash,
'addresses':addresses, 'phones':phones,
'vcard_str': unicode(VCard(contact)),
}))
elif request.method=="POST":
contact.delete()
return HttpResponseRedirect(reverse('addressbook_index'))
else:
raise Http404
我做错了什么?我怎样才能解决这个问题 ?
答案 0 :(得分:0)
您可以在utf-8中尝试编码:
'vcard_str': (VCard(contact)).encode("utf-8")
答案 1 :(得分:0)
在models.py中更新VCard的 str 方法来处理此异常。
questions.Controls.Remove(control);
control.Dispose();