Hi I want to use persian chracters in my url like:
localhost:8000/products/سامسونگ-گلکسی-اس22
that means in english:
localhost:8000/products/samsung-galaxy-s22
I writted this for slugify and slug field:
slug = md.SlugField(default='', null=False, blank=True, max_length=200, unique=True, allow_unicode=True,
verbose_name='عنوان در url')
and,
def save(self, *args, **kwargs):
self.slug = slugify(self.title, allow_unicode=True)
super().save(*args, **kwargs)
my url path:
path('<slug:slug>', views.ProductDetailView.as_view(), name='product-detail'),
it's working good and slugifies the title of product but when I want to use it the appliction returns 500 internal error and when I put an english title for product instead of the persian one the app works normally but with an english slug
Note: I imported models as md
CodePudding user response:
You should use <str:slug> instead of <slug:slug> in your url path cause slug only matches ascii chars, not persian letters.