Reputation: 527
I have a problem with using utf-8 characters in Model Forms in django. I have this code in model :
class Student (models.Model):
imie = models.CharField(verbose_name=u'Imię', max_length=40)
nazwisko = models.CharField(max_length=40)
(...)
def __unicode__(self):
return u'%s %s'(self.imie, self.nazwisko)
When i try to save this in a editor and run runserver command, the server sends Validating models... message and hangs, wihtout any error, and i can't refresh the page cause server can't start. When i insert normal (non unicode) in verbose_name='Imie' everything works great. What am i missing ?
Upvotes: 0
Views: 1725
Reputation: 1434
Set file encoding to UTF-8 by writing the following at the top of the file.
# coding=utf8
Then add a lower case u before the string.
verbose_name=u'Imię'
More info about encodings in Python in PEP 263.
Upvotes: 1
Reputation: 798606
You forgot to use a unicode
.
imie = models.CharField(verbose_name=u'Imię', max_length=40)
Upvotes: 0