[Answered ]-Django slug issue noreversematch

1👍

This will not work since your "slug" contains an invalid character. Indeed:

Cybercrime-Could-Cost-the-World-$10.5-Trillion-Annually-by-2025-aee2db6e-29ca-4ff9-94e8-09d8656905f3

contains a $, a slug however can not contain a $. The <slug:… path converter uses as regex [GitHub]:

class SlugConverter(StringConverter):
    regex = '[-a-zA-Z0-9_]+'

So it can only contain hyphens (-), alphanumerical characters, and an underscore.

You should slugify the title properly. You can do this with the slugify(…) function [Django-doc], for example:

>>> from django.utils.text import slugify
>>> slugify('Cybercrime Could Cost the World $10.5 Trillion Annually by 2025')
'cybercrime-could-cost-the-world-105-trillion-annually-by-2025'

I would advise to use this function instead of implementing your own slug function, since it contains some extra logic to remove diacritics, such that ù is for example transformed to u:

>>> slugify('più')
'piu'

Leave a comment