Здравствуйте, я живу в Польше, поэтому мне приходится иметь дело с такими письмами, как łóźć и т. Д. Когда я пытаюсь добавить в панели администратора текст, например "Zespół Szkół", я получаю сообщение об ошибке:
Поймано UnicodeEncodeError при рендеринге: кодек 'ascii' не может кодировать символы в позиции 4-5: порядковый номер не находится в диапазоне (128)
Я видел на странице Stackoverflow много подобных проблем, но я не вижуесть какие-либо идеи, как решить мой.
Моя база данных MySQL
Unicode коллекция для моей базы данных: utf8_unicode_ci
My models.py
# -*- coding: utf-8 -*-
from django.db import models
import codecs
...
class experience(models.Model):
dateStart = models.DateField()
dateEnd = models.DateField()
company = models.CharField(max_length=50)
position = models.CharField(max_length=50)
description = models.TextField(max_length=255)
def __unicode__(self):
return self.company.decode('utf8')
...
Traceback
Request Method: GET
Request URL: http://vm:8000/admin/mycv/experience/
Django Version: 1.3.1
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'cv.mycv']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Template error:
In template /usr/local/lib/python2.6/dist-packages/django/contrib/admin/templates/admin/change_list.html, error at line 97
Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode characters in position 4-5: ordinal not in range(128)
87 : {% endif %}
88 : {% endblock %}
89 :
90 : <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
91 : {% if cl.formset %}
92 : <div>{{ cl.formset.management_form }}</div>
93 : {% endif %}
94 :
95 : {% block result_list %}
96 : {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
97 : {% result_list cl %}
98 : {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
99 : {% endblock %}
100 : {% block pagination %}{% pagination cl %}{% endblock %}
101 : </form>
102 : </div>
103 : </div>
104 : {% endblock %}
105 :
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py" in wrapper
307. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py" in inner
197. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py" in _wrapper
28. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py" in bound_func
24. return func(self, *args2, **kwargs2)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py" in changelist_view
1179. ], context, context_instance=context_instance)
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string
188. return t.render(context_instance)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
123. return self._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
64. result = block.nodelist.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
73. result = node.render(context)
File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
921. dict = func(*args)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templatetags/admin_list.py" in result_list
232. 'results': list(results(cl))}
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templatetags/admin_list.py" in results
217. yield ResultList(None, items_for_result(cl, res, None))
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templatetags/admin_list.py" in __init__
209. super(ResultList, self).__init__(*items)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/templatetags/admin_list.py" in items_for_result
137. f, attr, value = lookup_field(field_name, result, cl.model_admin)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py" in lookup_field
218. value = attr()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py" in __str__
377. return force_unicode(self).encode('utf-8')
File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py" in force_unicode
71. s = unicode(s)
File "/home/lechu/apps/cv/../cv/mycv/models.py" in __unicode__
31. return self.company.decode('utf8')
File "/usr/lib/python2.6/encodings/utf_8.py" in decode
16. return codecs.utf_8_decode(input, errors, True)
Exception Type: TemplateSyntaxError at /admin/mycv/experience/
Exception Value: Caught UnicodeEncodeError while rendering: 'ascii' codec can't encode characters in position 4-5: ordinal not in range(128)
104 : {% endblock %}
105 :
Traceback:
File