2017-03-14 1 views
0

에서 UnicodeEncodeError를 인코딩합니다. 장고 프로젝트에 문제가 있습니다.django는/

UnicodeEncodeError은/접촉/1/뷰 'ASCII'코덱에 위치 28 바이트 0xd0을 디코딩 할 수없는 범위의 서수 (128)에서 역 추적

: single_contact

'vcard_str': unicode(VCard(contact)), 
에 views.py

모두보기 잘못하고 무엇 메신저

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

VCard의 'contact' 값에 원시 값을 제공 할 수 있습니까? –

답변

0

당신은 UTF-8 인코딩을 시도 할 수 있습니다 :

'vcard_str': (VCard(contact)).encode("utf-8") 
+0

'VCard'객체에는 'encode'속성이 없습니다 – tonyjasta

+0

@tonyjasta .. oops .. 어쨌든 내 대답 – Harsha

+0

을 업데이트했습니다. encode 속성과 동일한 오류가 있습니다. – tonyjasta

0

을 models.py 업데이트에서이 예외를 처리하는 vCard를의 STR 방법.

def __str__(self): 
     return self.name.encode('utf-8') 
+0

이 모델을 업데이트하는 경우 오류가 발생했습니다. /contact/2/view에서 유니 코드 데코레이션 오류가 발생했습니다. 'ascii'코덱은 1704 위치에서 바이트 0xd0을 디코딩 할 수 없습니다. – tonyjasta

관련 문제