5
To enable url encoder, simply open settings.py and at the end of file, insert as new line:
ALLOW_UNICODE_SLUGS = True
4
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
if not self.slug:
self.slug = arabic_slugify(self.title)
super(Note, self).save(*args, **kwargs)
def __str__(self):
return self.title
def arabic_slugify(str):
str = str.replace(" ", "-")
str = str.replace(",", "-")
str = str.replace("(", "-")
str = str.replace(")", "")
str = str.replace("Ψ", "")
return str
- [Django]-Django can't process non-ascii symbols
- [Django]-Running Gunicorn behind chrooted nginx inside virtualenv
- [Django]-Receiving error: django.core.exceptions.ImproperlyConfigured
1
It is better to use
allow_unicode=True
attr for each SlugField
that you want to make it allowing Unicode.
This is s simple example:
slug = models.SlugField(max_length=200, allow_unicode=True, unique=True)
For the new versions of Django
the settings.py
ALLOW_UNICODE_SLUGS = True
attribute will not work.
0
check this https://github.com/mozilla/unicode-slugify , I have use it with Django 1.4.x/1.5.x, I was also looking for Arabic slugs.
- [Django]-Deleting periodic task for celery scheduler in `settings.py` will not delete the actual task
- [Django]-Django admin with websocket
Source:stackexchange.com