[Django]-Django how to use generic view with UUID instead of PK

3๐Ÿ‘

โœ…

I added slug_url_kwarg = 'uuid' to the DetailView class and now it works BUT now I have a

AttributeError at /posti/qNwEXBxXQdGI4KlQfoHWOA/ Generic detail view DetailView must be called with either an object pk or a slug.

slug_url_kwarg must match your url regex group name (slug in your case, which is default value for slug_url_kwarg), so you shouldnโ€™t have changed it

For details look at the piece of Django source code here โ€“ https://github.com/django/django/blob/master/django/views/generic/detail.py#L8

Leave a comment