我有一个django测试项目,其中包含一个名为customers的表的postgresql数据库。 在/customers/中呈现所有客户很好,但我正在寻找一种方式来呈现单个客户,如下所示:/customer/{{{customer.id}。不太确定我在找什么,有没有人能帮我找到正确的文档或其他什么
非常感谢
列出所有客户并在单击div时打开给定客户:
<div class="container">
{% for customerz in custs_all %}
<br>
<div class="row shadow-sm d-flex w-1000 justify-content-between" onclick="location.href='/customers/{{customerz.id}}';" style="cursor: pointer;">
<div class="col-xl-4"><h5 class="mb-1">{{ customerz.name }}</h5></div>
<div class="col-xl-4">Contact person: {{ customerz.contactperson }}</div>
<div class="col-xl-4">Email: {{ customerz.email }}</div>
<div class="col-xl-4">Active: <span class="badge badge-light">{{ customerz.active }}</span></div>
</div>
{% endfor %}
</div>
这就是我不明白的,我需要读什么文件才能让它正常工作
onclick="location.href='/customers/{{customerz.id}}';"
我不知道我在找什么,所以很难在这里提出正确的问题。。对不起
我想你在找this。您可以在URL请求中传递ID,并使用它从数据库中获取所需的对象
views.py
这里pk是主键,所以您从模型客户(或您所命名的任何客户)中获取客户
urls.py
在客户列表模板中,您可以添加链接以添加客户详细信息模板,如
<a href="{% 'customer-detail' cutomer.pk %}"> cutomer detail </a>
相关问题 更多 >
编程相关推荐