找不到带有参数'('',)'的'program'反向。尝试了1个模式:['home /(?P <program_id> [0-9] +)/ program / $']

时间:2019-12-30 05:20:06

标签: python django django-models django-templates django-views

当我添加网址时显示此错误

        {% for prgmm in programinfo.all %}
      <a href="{% url 'program' prgm.id %}">

                 <div id="prgmm" style="width:50%">
                   <img src="{{ prgmm.titleimage.url }}" alt="">
                 </div>
      </a>

我的网址是:

urlpatterns = [
    path('', views.homepage, name='home'),
    path('<int:services_id>/', views.details, name='details'),
    path('<int:prgm_id>/program/', views.program, name='program')

和我的观点:

    def program(request, prgm_id):
programdetail = get_object_or_404(prgm, pk=prgm_id)
return render(request, 'program.html', {'programdetail': programdetail})

2 个答案:

答案 0 :(得分:0)

将您的代码<a href="{% url 'program' prgm.id %}">更改为<a href="{% url 'program' prgmm.id %}">

答案 1 :(得分:0)

您在网址部分写了“ prgm.id”而不是“ prgmm.id”