Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python slugify()得到一个意外的关键字参数';允许使用unicode';_Python_Django_Django Models_Slug_Django 2.2 - Fatal编程技术网

Python slugify()得到一个意外的关键字参数';允许使用unicode';

Python slugify()得到一个意外的关键字参数';允许使用unicode';,python,django,django-models,slug,django-2.2,Python,Django,Django Models,Slug,Django 2.2,当我想从product创建新对象时,出现以下错误: slugify()得到一个意外的关键字参数“allow\u unicode” 这是我的模型: class BaseModel(models.Model): created_date = models.DateTimeField(auto_now_add=True) modified_date = models.DateTimeField(auto_now=True,) slug = models.SlugField(nu

当我想从
product
创建新对象时,出现以下错误:

slugify()得到一个意外的关键字参数“allow\u 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)
我还为其他应用程序(博客)运行了相同的模式,在那里我没有遇到这个问题。
此应用程序有什么问题?

升级Django,即版本1.9中引入的参数
allow_unicode
,或在没有该参数的情况下调用该函数。

由于
slagify
函数在其他应用程序中工作,这意味着您使用了不同的函数,至少在该文件中通过
slugify
标识符引用。这可能有几个原因:

  • 您导入了错误的
    slagify
    函数(例如
  • 您确实导入了正确的函数,但后来在文件中导入了另一个名为
    slagify
    (可能通过别名或通配符导入)的函数;或者
  • 您在文件中定义了名为
    slagify
    的类或函数(可能是在导入
    slagify
    之后)
  • 不管原因如何,它都指向“错误”函数,因此无法处理命名参数
    allow\u unicode


    您可以通过重新组织导入,或为函数/类名指定其他名称来解决此问题。

    您可能已经在某个地方覆盖了
    slagify
    ,方法是导入其他名为
    slagify
    ,或在该文件中定义名为
    slagify
    的函数或类。哦,我的天啊!您是对的!我先生kenly从django.template.defaultfilters导入slugify
    ,然后从django.utils.text导入slugify
    ,在我的博客应用程序和店内应用程序的
    模型中导入
    。我没有从django.utils.text导入slugify.
    。请写下你的答案接受。@WillemVanonEmperfect答案。谢谢@威廉·范昂森