今天试玩了一个Django框架,感觉还不错,试着添加中文内容出现
UnicodeEncodeError
Google 百度搜索了很多,问题也多样,最终解决却只是简单一句
class Article(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
content = models.TextField()
pub_date = models.DateField()
category = models.ForeignKey(ArticleCategory)
def __unicode__(self): #原来是__str__(self) 输中文的时候会出现编码错误的异常
return u'%s' % (self.title)
class Admin:
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
content = models.TextField()
pub_date = models.DateField()
category = models.ForeignKey(ArticleCategory)
def __unicode__(self): #原来是__str__(self) 输中文的时候会出现编码错误的异常
return u'%s' % (self.title)
class Admin:
pass