Aayush Gupta
Aayush Gupta

Reputation: 502

Template not showing data (is blank) fetched from sqlite using view function by passing a parameter

I have implemented a feature where there is a "view" button next to each row fetched from the DB. When clicked it is sending the id of the event to view URL. The view then fetches the filtered data from SQLite; but it is not showing the data in the template.

template.html

<td><a href="{% url 'event' eid=ev.id %}">View</a></td>

urls.py

path('<int:eid>', views.event_det, name='event'),

views.py

def event_det(request, eid):
    data = Event.objects.filter(id=eid)
    return render(request, 'event_details.html', {'event': data})

template.html to show the fetched output

{% for ev in event %}
        <div class="card mb-12">
            <div class="row no-gutters">
                <div class="col-md-12">
                    <img src="{% static 'face_detector/datasets/9187/color-1.png' %}" class="card-img" alt="...">
                </div>
                <div class="col-md-12">
                    <div class="card-body">
                        <h2 class="card-title">{{ ev.name }}</h2>
                        <p class="card-text">{{ ev.description }}</p>
                        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
                    </div>
                </div>
...

Upvotes: 2

Views: 169

Answers (1)

Matt Seymour
Matt Seymour

Reputation: 9415

A common issue is that your urls.py might have duplicate entries or a duplicate valid entry. In this case the first path to match will be evaluated and eventually rendered.

Please check your urls.py for any paths which might be called by mistake.

Upvotes: 1

Related Questions