Define navigation link from list view to detail view in Django - 15

Video thumbnail

Now, once the detail view has been created with the navigation link so as not to reach it directly, we will place it in the Index. Here we have the Bootstrap menu. Here we have the description. We can place it down here. We place a label. We place the routes:

mystore\elements\templates\elements\index.html

<div class="card-body">
   <p>{{e.description}}</p>
   <a class="btn btn-sm btn-outline-primary" href="{% url 'elements:detail' e.id %}">Go</a>
</div>

Note that we are indicating the name of the application as a prefix:

elements:

You could define it as follows:

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

But indicating the name of the application makes it more reusable.

In order to reference the name of the application, we must define the namespace:

mystore\mystore\urls.py

path('store/', include('elements.urls', namespace='elements')),

To avoid an error like the following:

ImproperlyConfiguredError about app_name when using namespace in include()

And the:

mystore\elements\urls.py

app_name = 'elements'

To avoid an error like the following:

is not a registered namespace

I agree to receive announcements of interest about this Blog.

We create the navigation button.

- 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.