0

我在将 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/
4

1 回答 1

0

也许您需要在您的网址中设置 app_name

from . import views
from django.urls import path

app_name = 'academy'

urlpatterns=[
    path('add_academy/<int:pk>/',views.add_academy, name='add_academy')
]
于 2020-03-26T14:04:52.827 回答