我在将 id 传递给模板时遇到了困难。这是我的views.py文件
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)
这也是我的 urls.py 文件
from . import views
from django.urls import path
urlpatterns=[
path('add_academy/<int:pk>/',views.add_academy, name='add_academy')
]
这是我的模板
<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>
它向我显示了一个错误,指出
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/