我对Django/Python比较陌生
在标题中生成NoReverseMatch错误的my index.html代码行如下所示
<a href="{% url 'ipads_by_school' school_id=LES %}" class="btn btn-outline-primary m-1" >LES</a>
这是我的url.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')
]
这是我的观点
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)
目前没有回答
相关问题 更多 >
编程相关推荐