【发布时间】:2019-12-11 21:13:10
【问题描述】:
当我想从product 创建新对象时,我收到了这个错误:
slugify() got an unexpected keyword argument 'allow_unicode'
这是我的模型:
class BaseModel(models.Model):
created_date = models.DateTimeField(auto_now_add=True)
modified_date = models.DateTimeField(auto_now=True,)
slug = models.SlugField(null=True, blank=True, unique=True, allow_unicode=True, max_length=255)
class Meta:
abstract = True
class Product(BaseModel):
author = models.ForeignKey(User)
title = models.CharField()
# overwrite your model save method
def save(self, *args, **kwargs):
title = self.title
# allow_unicode=True for support utf-8 languages
self.slug = slugify(title, allow_unicode=True)
super(Product, self).save(*args, **kwargs)
我也为其他应用程序(博客)运行了相同的模式,我没有遇到这个问题。 这个应用有什么问题?
【问题讨论】:
-
您可能已经在某处覆盖了
slugify,方法是导入名称为slugify的其他内容,或者在该文件中定义名称为slugify的函数或类。 -
天哪!你是对的!我在我的博客应用程序的
models.py和商店应用程序中错误地导入了from django.template.defaultfilters import slugify,然后是from django.utils.text import slugify,我没有导入from django.utils.text import slugify.。请写下您的答案以接受。 @WillemVanOnsem
标签: python django django-models slug django-2.2