django详细信息页面未链接到详细信息页面ID

时间:2020-07-13 01:12:28

标签: django

blog.html

<a href="/detail/{{ detail.id }}/" class="text-dark">{{ cmccDemo.summary }}</a>

url.py

path('detail/<int:id>/', cmccDemos.views.detail, name='detail'),

views.py

def detail(request, id=None):
    cmccDemo_detail = get_object_or_404(CmccDemo, id=id)
    return render(request, 'cmccDemos/detail.html', {'cmccDemo': cmccDemo_detail})

但是,当我单击博客以获取详细信息时,它会将我定向到URL:http://127.0.0.1:8000/detail// 当我手动放置http://127.0.0.1:8000/detail/1/时,它会起作用。

1 个答案:

答案 0 :(得分:1)

这应该可以解决问题

<a href="{% url 'detail' cmccDemo.id %}" class="text-dark">{{ cmccDemo.summary }}</a>