Post details using slug instead of PK in Django - 32

From this video we are going to start to solve some small situations, some small problems that we left pending in this case it is referring to what the slug is since we are not using it here, we are looking for it is by the PK which I obviously do not want because for something we configured the slug So for that nothing easier:

mystore\elements\views.py

def detail(request, slug):
   element = Element.objects.get(slug=slug)
   ***

The route:

mystore\elements\urls.py

path('<str:slug>', views.detail, name='detail'),

And the template:

mystore\elements\templates\elements\index.html

<a class="btn btn-sm btn-outline-primary" href="{% url 'elements:detail' e.slug %}">Go</a>

I agree to receive announcements of interest about this Blog.

We will create a link to get the publication details using the slug and not the PK.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro desarrollo web con Django 5 y Python 3 + integración con Vue 3, Bootstrap y Alpine.js.