[Django]-Django DetailView failing to find object based on SLUG

4👍

Django’s slugify method:

Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace.

you are looking for a Camel Case’d tag:

http://localhost:9999/tag/RandomTag/

you need to use lowercase:

http://localhost:9999/tag/randomtag/  # or `random-tag` depending on the name

Check your DB to see exactly how the slug is saved

1👍

Timmy’s answer is correct in ascertaining the problem — slugs are lowercase. He suggests you use a lowercase url. Not a bad solution… but perhaps you like the url like that?

If you want the slug to be case insensitive, set slug_field = 'slug__iexact' on your view.

👤meshy

Leave a comment