我在将我的django项目迁移到heroku时遇到了一些问题。在执行heroku运行python manage.py syncdb并输入超级用户和密码时,我收到以下错误消息。类型错误导致的Django错误:必须是unicode不是str
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/text.py", line 409, in slugify
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
TypeError: must be unicode, not str
我的models.py
from django.db import models
from django.db.models.signals import post_save
from django.conf import settings
from django.contrib.auth.models import User
from autoslug import AutoSlugField
# Create your models here.
class Profile(models.Model):
account = models.OneToOneField(User, unique=True)
name = models.CharField(max_length = 120, null=True, blank=True)
location = models.CharField(max_length = 120, null=True, blank=True)
website = models.CharField(max_length = 120, null=True, blank=True)
bio = models.CharField(max_length = 120, null=True, blank=True)
timestamp = models.DateTimeField(auto_now = False, auto_now_add=True)
updated_timestamp = models.DateTimeField(auto_now = True, auto_now_add=False)
slug = AutoSlugField(populate_from="account")
@models.permalink
def get_absolute_url(self):
return ('view_profile', None, {'username': self.account.username})
def __unicode__(self):
return str(self.account.username)
# here is the profile model
def user_post_save(sender, instance, created, **kwargs):
"""Create a user profile when a new user account is created"""
if created == True:
p = Profile()
p.account = instance
p.save()
post_save.connect(user_post_save, sender=User)
'self.account.username' is * a已经* unicode值。如果不是,你可以使用'unicode(self.account.username)'。 – 2014-09-27 15:28:20
我试过了,它不起作用。我会尝试@MartijnPieters的答案 – cloudviz 2014-09-27 15:36:51
@cloudviz:你没有包括你的整个回溯,所以我不得不做一些猜测;皮埃尔也做了,没有猜对。获得的经验:下一次包括整个回溯。 – 2014-09-27 15:37:39