我是Django / Python的新手。
我的index.html中的代码行在标题中生成了NoReverseMatch错误。
<a href="{% url 'ipads_by_school' school_id=LES %}" class="btn btn-outline-primary m-1" >LES</a>
这是我的urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<str:school_id>', views.ipads_by_school, name='ipads_by_school')
]
这是我的views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import Ipad
def index(request):
return render(request, 'ipads/index.html')
def ipads_by_school(request, school_id):
school_ipads = Ipad.objects.filter(school_id__icontains=school_id)
context = {
'school_ipads': school_ipads
}
return render(request, 'ipads/ipads_by_school.html', context)