相关疑难解决方法(0)

如何在django中设置表的char列的编码?

我有一个用Django编写的项目.应该存储一些字符串的所有字段都应该是UTF-8,但是,当我运行时

manage.py syncdb
Run Code Online (Sandbox Code Playgroud)

所有相应的列都是用cp1252字符集创建的(它在哪里得到了 - 我不知道)我必须手动更新每一列......

有没有办法告诉Django首先使用UTF-8编码创建所有这些列?

顺便说一句,我使用MySQL.

python mysql django

13
推荐指数
1
解决办法
9607
查看次数

Django头痛与简单的非ascii字符串

我刚刚创建了以下模型:

class Categoria(models.Model):
    nombre=models.CharField(max_length=30)
    padre=models.ForeignKey('self', blank=True, null=True)

    def __unicode__(self):
        return self.nombre
Run Code Online (Sandbox Code Playgroud)

然后注册到管理界面和syncdb'd

如果我只添加纯ASCII字符,一切都OK.但如果我添加一个名为"á"的"类别"(说些什么),我会得到:

Environment:

Request Method: GET
Request URL: http://192.168.2.103:8000/administracion/locales/categoria/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'cruzandoelsuquiaDJ.locales']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Template error:
In template /usr/lib/pymodules/python2.6/django/contrib/admin/templates/admin/change_list.html, error at line 78
   Caught an exception while rendering: ('ascii', '\xc3\xa1', 0, 1, 'ordinal not in range(128)')
   68 :         {% endif %}


   69 :       {% endblock %}


   70 :       


   71 :       <form action="" method="post"{% if cl.formset.is_multipart %} …
Run Code Online (Sandbox Code Playgroud)

unicode django-admin

8
推荐指数
2
解决办法
9457
查看次数

标签 统计

django ×1

django-admin ×1

mysql ×1

python ×1

unicode ×1