Detail View by ID in Django - 14

Once the list view with pagination has been defined, we now move on to the detail page:

mystore\elements\templates\elements\detail.html


{% extends "base.html" %}

{% block content %}
<div class="card">
    <div class="card-header">
        <h1>{{ element.title }}</h1>
    </div>

    <div class="card-body">
        <div>
            {{element.description}}
        </div>

        <div>
            {{element.content}}
        </div>
    </div>
</div>

{% endblock %}

As you can see, it is a simple template with the details of the publication and it is processed from the view:

def detail(request, pk):

    element = Element.objects.get(id=pk)
    return render(request,'elements/detail.html',
                  {'element': element }

I agree to receive announcements of interest about this Blog.

We enabled pagination in the application.

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

) )