【发布时间】:2014-11-22 10:33:10
【问题描述】:
将我的 django 项目迁移到 heroku 时遇到了一些问题。执行 heroku run python manage.py syncdb 然后输入超级用户和密码时出现以下错误。
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
我的模型.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)
【问题讨论】:
标签: python django signals slug