Home > Mobile >  Reverse for 'db' with arguments '('',)' not found. 1 pattern(s) tried:
Reverse for 'db' with arguments '('',)' not found. 1 pattern(s) tried:

Time:12-15

when I am trying to grab items from db.html with the help of id it is showing an error I cant understand where is the problem please help me out

venue.html

{% extends 'MYapp/index.html' %}
{% block content %}

<center>
    <h1> venue.html </h1>
    <br>



    <div >
        Featured
    </div>

    <div >
        <h5 >Special title treatment</h5>
        {% for venues in venue_list %}
        <p >


            <a href="{% url 'db' all.id %}"> {{ venues }} {{ venues.lastname}}</a>
            {% endfor %}
        </p>

    </div>

</center>


{% endblock %}

views.py

 from django.shortcuts import render
 from django.http import *
 from  MYapp.models import *
 from .form import *



 def index(request):
    return render(request,'MYapp/index.html')
 def venue(request):
    venue_list = Task.objects.all()
    return render(request,'MYapp/venue.html',{'venue_list': venue_list})
 def db(request, db_id):
    all = Task.objects.get(pk= db_id)
    return render(request,'MYapp/db.html',{'all': all})

urls.py

another error occers hear

it is showing page is not found

because of this path('db/<db_id>/', views.db, name ='db'),

from django.contrib import admin
from django.urls import path
from . import views



urlpatterns = [

    path('nature', views.nature, name ='nature'),
    path('', views.index, name ='index'),

    path('footer', views.footer, name ='footer'),

    path('navebar', views.navebar, name ='navebar'), 

    path('form', views.form, name ='form'),
    path('venue', views.venue, name ='venue'),
    path('db/<db_id>/', views.db, name ='db'),

]

CodePudding user response:

When you render the template venue.html (in the view function called venue()), you are not passing the variable all to the context, you are just passing venue_list.

That causes the error because in the template in the part href="{% url 'db' all.id %}", the variable all will not be defined.

CodePudding user response:

I found that error because of putting wrong url in path

      <p >


            <a href="{% url 'db' all.id %}"> {{ venues }} {{ 
            venues.lastname}}</a>
            {% endfor %}
      </p>

change the name of variable to venues because u did it in for loop then

            <a href="{% url 'db' venues.id %}"> {{ venues }} {{ 
            venues.lastname}}</a>
            {% endfor %}
      </p>
  • Related