Unicode convertion problem in django view
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a queryset in Django view :
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname'))
There are some characters that causes UnicodeDecodeError exception.Teacher_fullname or teacher_surname may have these characters. So that it gives below warning:
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
The string that could not be encoded/decoded was: John ��. YI
I am trying to write this string to excell worksheet as below :
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
.encode('utf-8') seems not solving the problem
Using Django 1.9.5 and Python 2.7.5
Full traceback is :
Traceback:
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "./college/views.py" in print_course_teacher
1341. workbook.close()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in close
306. self._store_workbook()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in _store_workbook
649. xml_files = packager._create_package()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _create_package
140. self._write_shared_strings_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _write_shared_strings_file
287. sst._assemble_xml_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _assemble_xml_file
54. self._write_sst_strings()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_sst_strings
84. self._write_si(string)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_si
122. self._xml_si_element(string, attributes)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/xmlwriter.py" in _xml_si_element
122. self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
691. return self.writer.write(data)
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
351. data, consumed = self.encode(object, self.errors)
Exception Type: UnicodeDecodeError at /print-course-teacher/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
Original code is :
worksheet.write(teachersrow, item['teacher_fullname'], cellformat)
View code in contex :
uuidlist =
for classuuid in optional_class_object:
uuidlist.append(classuuid['uuid'])
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')) | CourseTeacher.objects.filter(cls__uuid=cls_uuid).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')).order_by("cls__name")
last_semester = "2017-2018"
workbook = xlsxwriter.Workbook('table.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write("A2", "Semester [ "+str(last_semester)+" ] ")
cellformat = workbook.add_format({
'border': 1,
'align': 'left',
'valign': 'top',
'fg_color': 'white'})
row = 4
for item in queryset.values('cls__year', 'cls__name', 'course__code', 'course__name', 'teacher_fullname', 'credit', 'hours_weekly').reverse():
classrow = "A"+str(row)
coursecoderow = "B"+str(row)
coursenamerow = "C"+str(row)
creditrow = "D"+str(row)
hoursweeklyrow = "E"+str(row)
teachersrow = "F"+str(row)
worksheet.write(classrow, str(item['cls__year'])+""+item['cls__name'], cellformat)
worksheet.write(coursecoderow, item['course__code'].encode('utf-8'), cellformat)
worksheet.write(coursenamerow, item['course__name'].encode('utf-8'), cellformat)
worksheet.write(creditrow, item['credit'], cellformat)
worksheet.write(hoursweeklyrow, item['hours_weekly'], cellformat)
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
row = row + 1
workbook.close()
with open("table.xlsx", 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename("table.xlsx")
os.remove("table.xlsx")
return response
python django django-views django-queryset
add a comment |
I have a queryset in Django view :
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname'))
There are some characters that causes UnicodeDecodeError exception.Teacher_fullname or teacher_surname may have these characters. So that it gives below warning:
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
The string that could not be encoded/decoded was: John ��. YI
I am trying to write this string to excell worksheet as below :
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
.encode('utf-8') seems not solving the problem
Using Django 1.9.5 and Python 2.7.5
Full traceback is :
Traceback:
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "./college/views.py" in print_course_teacher
1341. workbook.close()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in close
306. self._store_workbook()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in _store_workbook
649. xml_files = packager._create_package()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _create_package
140. self._write_shared_strings_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _write_shared_strings_file
287. sst._assemble_xml_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _assemble_xml_file
54. self._write_sst_strings()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_sst_strings
84. self._write_si(string)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_si
122. self._xml_si_element(string, attributes)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/xmlwriter.py" in _xml_si_element
122. self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
691. return self.writer.write(data)
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
351. data, consumed = self.encode(object, self.errors)
Exception Type: UnicodeDecodeError at /print-course-teacher/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
Original code is :
worksheet.write(teachersrow, item['teacher_fullname'], cellformat)
View code in contex :
uuidlist =
for classuuid in optional_class_object:
uuidlist.append(classuuid['uuid'])
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')) | CourseTeacher.objects.filter(cls__uuid=cls_uuid).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')).order_by("cls__name")
last_semester = "2017-2018"
workbook = xlsxwriter.Workbook('table.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write("A2", "Semester [ "+str(last_semester)+" ] ")
cellformat = workbook.add_format({
'border': 1,
'align': 'left',
'valign': 'top',
'fg_color': 'white'})
row = 4
for item in queryset.values('cls__year', 'cls__name', 'course__code', 'course__name', 'teacher_fullname', 'credit', 'hours_weekly').reverse():
classrow = "A"+str(row)
coursecoderow = "B"+str(row)
coursenamerow = "C"+str(row)
creditrow = "D"+str(row)
hoursweeklyrow = "E"+str(row)
teachersrow = "F"+str(row)
worksheet.write(classrow, str(item['cls__year'])+""+item['cls__name'], cellformat)
worksheet.write(coursecoderow, item['course__code'].encode('utf-8'), cellformat)
worksheet.write(coursenamerow, item['course__name'].encode('utf-8'), cellformat)
worksheet.write(creditrow, item['credit'], cellformat)
worksheet.write(hoursweeklyrow, item['hours_weekly'], cellformat)
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
row = row + 1
workbook.close()
with open("table.xlsx", 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename("table.xlsx")
os.remove("table.xlsx")
return response
python django django-views django-queryset
Please show the full traceback, and the code you tried originally before addingencode.
– Daniel Roseman
Nov 16 '18 at 13:04
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Added code in context
– ivbtar
Nov 16 '18 at 13:55
add a comment |
I have a queryset in Django view :
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname'))
There are some characters that causes UnicodeDecodeError exception.Teacher_fullname or teacher_surname may have these characters. So that it gives below warning:
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
The string that could not be encoded/decoded was: John ��. YI
I am trying to write this string to excell worksheet as below :
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
.encode('utf-8') seems not solving the problem
Using Django 1.9.5 and Python 2.7.5
Full traceback is :
Traceback:
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "./college/views.py" in print_course_teacher
1341. workbook.close()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in close
306. self._store_workbook()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in _store_workbook
649. xml_files = packager._create_package()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _create_package
140. self._write_shared_strings_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _write_shared_strings_file
287. sst._assemble_xml_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _assemble_xml_file
54. self._write_sst_strings()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_sst_strings
84. self._write_si(string)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_si
122. self._xml_si_element(string, attributes)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/xmlwriter.py" in _xml_si_element
122. self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
691. return self.writer.write(data)
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
351. data, consumed = self.encode(object, self.errors)
Exception Type: UnicodeDecodeError at /print-course-teacher/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
Original code is :
worksheet.write(teachersrow, item['teacher_fullname'], cellformat)
View code in contex :
uuidlist =
for classuuid in optional_class_object:
uuidlist.append(classuuid['uuid'])
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')) | CourseTeacher.objects.filter(cls__uuid=cls_uuid).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')).order_by("cls__name")
last_semester = "2017-2018"
workbook = xlsxwriter.Workbook('table.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write("A2", "Semester [ "+str(last_semester)+" ] ")
cellformat = workbook.add_format({
'border': 1,
'align': 'left',
'valign': 'top',
'fg_color': 'white'})
row = 4
for item in queryset.values('cls__year', 'cls__name', 'course__code', 'course__name', 'teacher_fullname', 'credit', 'hours_weekly').reverse():
classrow = "A"+str(row)
coursecoderow = "B"+str(row)
coursenamerow = "C"+str(row)
creditrow = "D"+str(row)
hoursweeklyrow = "E"+str(row)
teachersrow = "F"+str(row)
worksheet.write(classrow, str(item['cls__year'])+""+item['cls__name'], cellformat)
worksheet.write(coursecoderow, item['course__code'].encode('utf-8'), cellformat)
worksheet.write(coursenamerow, item['course__name'].encode('utf-8'), cellformat)
worksheet.write(creditrow, item['credit'], cellformat)
worksheet.write(hoursweeklyrow, item['hours_weekly'], cellformat)
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
row = row + 1
workbook.close()
with open("table.xlsx", 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename("table.xlsx")
os.remove("table.xlsx")
return response
python django django-views django-queryset
I have a queryset in Django view :
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname'))
There are some characters that causes UnicodeDecodeError exception.Teacher_fullname or teacher_surname may have these characters. So that it gives below warning:
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
The string that could not be encoded/decoded was: John ��. YI
I am trying to write this string to excell worksheet as below :
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
.encode('utf-8') seems not solving the problem
Using Django 1.9.5 and Python 2.7.5
Full traceback is :
Traceback:
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "./college/views.py" in print_course_teacher
1341. workbook.close()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in close
306. self._store_workbook()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/workbook.py" in _store_workbook
649. xml_files = packager._create_package()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _create_package
140. self._write_shared_strings_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/packager.py" in _write_shared_strings_file
287. sst._assemble_xml_file()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _assemble_xml_file
54. self._write_sst_strings()
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_sst_strings
84. self._write_si(string)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/sharedstrings.py" in _write_si
122. self._xml_si_element(string, attributes)
File "/home/myproject/Env/myproject/lib/python2.7/site-packages/xlsxwriter/xmlwriter.py" in _xml_si_element
122. self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
691. return self.writer.write(data)
File "/home/myproject/Env/myproject/lib64/python2.7/codecs.py" in write
351. data, consumed = self.encode(object, self.errors)
Exception Type: UnicodeDecodeError at /print-course-teacher/
Exception Value: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
Original code is :
worksheet.write(teachersrow, item['teacher_fullname'], cellformat)
View code in contex :
uuidlist =
for classuuid in optional_class_object:
uuidlist.append(classuuid['uuid'])
queryset = CourseTeacher.objects.filter(cls__uuid__in=uuidlist).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')) | CourseTeacher.objects.filter(cls__uuid=cls_uuid).annotate(teacher_fullname=Concat('teacher__name', V(' '), 'teacher__surname')).order_by("cls__name")
last_semester = "2017-2018"
workbook = xlsxwriter.Workbook('table.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write("A2", "Semester [ "+str(last_semester)+" ] ")
cellformat = workbook.add_format({
'border': 1,
'align': 'left',
'valign': 'top',
'fg_color': 'white'})
row = 4
for item in queryset.values('cls__year', 'cls__name', 'course__code', 'course__name', 'teacher_fullname', 'credit', 'hours_weekly').reverse():
classrow = "A"+str(row)
coursecoderow = "B"+str(row)
coursenamerow = "C"+str(row)
creditrow = "D"+str(row)
hoursweeklyrow = "E"+str(row)
teachersrow = "F"+str(row)
worksheet.write(classrow, str(item['cls__year'])+""+item['cls__name'], cellformat)
worksheet.write(coursecoderow, item['course__code'].encode('utf-8'), cellformat)
worksheet.write(coursenamerow, item['course__name'].encode('utf-8'), cellformat)
worksheet.write(creditrow, item['credit'], cellformat)
worksheet.write(hoursweeklyrow, item['hours_weekly'], cellformat)
worksheet.write(teachersrow, item['teacher_fullname'].encode('utf-8'), cellformat)
row = row + 1
workbook.close()
with open("table.xlsx", 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename("table.xlsx")
os.remove("table.xlsx")
return response
python django django-views django-queryset
python django django-views django-queryset
edited Nov 16 '18 at 13:55
ivbtar
asked Nov 16 '18 at 12:48
ivbtarivbtar
140110
140110
Please show the full traceback, and the code you tried originally before addingencode.
– Daniel Roseman
Nov 16 '18 at 13:04
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Added code in context
– ivbtar
Nov 16 '18 at 13:55
add a comment |
Please show the full traceback, and the code you tried originally before addingencode.
– Daniel Roseman
Nov 16 '18 at 13:04
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Added code in context
– ivbtar
Nov 16 '18 at 13:55
Please show the full traceback, and the code you tried originally before adding
encode.– Daniel Roseman
Nov 16 '18 at 13:04
Please show the full traceback, and the code you tried originally before adding
encode.– Daniel Roseman
Nov 16 '18 at 13:04
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Added code in context
– ivbtar
Nov 16 '18 at 13:55
Added code in context
– ivbtar
Nov 16 '18 at 13:55
add a comment |
1 Answer
1
active
oldest
votes
Solved,
The code was ok as Daniel Roseman stated.
I checked the DB and found that table collation was latin1.
I changed it to utf-8. Now it works.
alter table class_teacher convert to character set utf8 collate utf8_general_ci;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338256%2funicode-convertion-problem-in-django-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solved,
The code was ok as Daniel Roseman stated.
I checked the DB and found that table collation was latin1.
I changed it to utf-8. Now it works.
alter table class_teacher convert to character set utf8 collate utf8_general_ci;
add a comment |
Solved,
The code was ok as Daniel Roseman stated.
I checked the DB and found that table collation was latin1.
I changed it to utf-8. Now it works.
alter table class_teacher convert to character set utf8 collate utf8_general_ci;
add a comment |
Solved,
The code was ok as Daniel Roseman stated.
I checked the DB and found that table collation was latin1.
I changed it to utf-8. Now it works.
alter table class_teacher convert to character set utf8 collate utf8_general_ci;
Solved,
The code was ok as Daniel Roseman stated.
I checked the DB and found that table collation was latin1.
I changed it to utf-8. Now it works.
alter table class_teacher convert to character set utf8 collate utf8_general_ci;
answered Nov 16 '18 at 14:09
ivbtarivbtar
140110
140110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338256%2funicode-convertion-problem-in-django-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please show the full traceback, and the code you tried originally before adding
encode.– Daniel Roseman
Nov 16 '18 at 13:04
I added full traceback and code before adding encode
– ivbtar
Nov 16 '18 at 13:26
I am using Centos 7. Python 2.7.5
– ivbtar
Nov 16 '18 at 13:28
Hmm, this should work. Can you show that code in context, from where you create the worksheet and the queryset?
– Daniel Roseman
Nov 16 '18 at 13:41
Added code in context
– ivbtar
Nov 16 '18 at 13:55