找不到带有关键字参数'{'school_id':''}'的'ipads_by_school'。尝试了1个模式:['(?P <school_id> [^ /] +)$']-Django

时间:2019-02-10 20:13:24

标签: python django

我是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)

0 个答案:

没有答案