首页 > 解决方案 > 找不到页面 (404) 请求方法:GET 请求 URL:http://127.0.0.1:4000/person/persondetails/3

问题描述

人员列表在 中完美显示person.html,但是当我单击 persondetails锚标记时出现错误。请让我知道如何纠正这个问题。

标签: pythondjangodjango-views

解决方案


在您的 urls.py 中,您已添加,persondetails/pk..因此它会将您重定向到 url,例如 id 3,

http://127.0.0.1:4000/persondetails/3/

您可以将其添加到 ..person/persondetail/pk...

为了更好的安排,views.py,

class PersonDetailPageView(DetailView):
     model = Your_Model_Name
     template_name = 'your_template_name.html'

在 html 中,

<a href="{% url 'persondetails' person.id %}"> your template </a>

推荐阅读