[英]How do I make the edit and cancel link appear only if its the logged in user is the one who created the object? Django
The edit and delete function works fine but I cant make it specific that it only appears to the person that created that object?编辑和删除 function 工作正常,但我不能具体说明它只出现在创建 object 的人身上?
{% for job in jobs %}
<tr>
<td>{{ job.job }}</td>
<td>{{ job.location }}</td>
<td><a href="/jobs/{{ job.id }}/view">View</a> <a href="/main">Add</a> <a href="/jobs/{{ job.id }}/edit">Edit</a> <a href="/jobs/{{ job.id }}/delete">Cancel</a> </td>
</tr>
{% endfor %}
Inside for
loop you can check if it's the same user who created it and if succeed
display button otherwise no need to append buttons as在
for
循环中,您可以检查是否是创建它的同一用户,如果succeed
显示按钮,则不需要 append 按钮
{% for job in jobs %}
<tr>
<td>{{ job.job }}</td>
<td>{{ job.location }}</td>
<td><a href="/jobs/{{ job.id }}/view">View</a>
<a href="/main">Add</a>
{% if job.creator == request.user %}
<a href="/jobs/{{ job.id }}/edit">Edit</a>
<a href="/jobs/{{ job.id }}/delete">Cancel</a>
{% endif %}
</td>
</tr>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.