0

I am getting stuck passing an id into the template. Here is my views.py file

def add_academy(request,pk):
    child=get_object_or_404(Child_detail,pk=pk)
    academy=Academic.objects.filter(Student_name=child)
    context={
        'academy':academy,
    }

    return render(request,'functionality/more/academy/add.html',context)

Also this my urls.py file

from . import views
from django.urls import path

urlpatterns=[
    path('add_academy/<int:pk>/',views.add_academy, name='add_academy')
]

And this is my template

<div class="container">
    <td><a href="{% url 'add_academy' child.id  %}">
        <button type="button" class="btn btn-primary">Add Academic details of a child</button>
        </a>
    </td>

It shows me an error that states that

NoReverseMatch at /academy/add_academy/3/
Reverse for 'academy' not found. 'academy' is not a valid view function or pattern name.
Request Method: GET
Request URL:    http://127.0.0.1:8000/academy/add_academy/3/
David Buck
  • 3,752
  • 35
  • 31
  • 35
Regnald Terry
  • 48
  • 1
  • 5

1 Answers1

0

maybe you need to set app_name in your urls

from . import views
from django.urls import path

app_name = 'academy'

urlpatterns=[
    path('add_academy/<int:pk>/',views.add_academy, name='add_academy')
]
Luiz
  • 1,985
  • 6
  • 16