Search code examples
djangoarabic

Django slug field in Arabic and other foreign languages


am trying to build an app with a model which contains a unique of the title, some users will write the title in Arabic and other languages and when on save, I try to slugify the field. It would return blank in case of Arabic. Any way to show arabic wordings but maintain slug principles of replacing special characters and spaces with dash?

class Article(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField()

   def save(self, *args, **kwargs):
     if self.slug is in (None, '', u''):
       self.slug = slugify(self.title)
     super(Article, self).save(*args, **kwargs)

Solution

  • To enable url encoder, simply open settings.py and at the end of file, insert as new line:

    ALLOW_UNICODE_SLUGS = True