我想让删除锚显示或隐藏,但删除锚不可见。
detail.html
{% if user.username == obj.con_id %}
<a href="{% url 'consignment:delete' obj.id %}">delete</a>
{% endif %}
我检查了模板,可以看到值
{{user.username}} --> user1
{{obj.con_id}} --> user1
这是我的观点,模型
views.py
def congsignmentDetail(request,detail_id):
obj = get_object_or_404(ConsignmentInfo,id=detail_id)
return render(request,'consignment/detail.html',{'obj':obj})
models.py
class ConsignmentInfo(models.Model):
con_id = models.Foreignkey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
......
答案 0 :(得分:2)
obj.con_id
是User
对象,而不是字符串。因此,您应该比较两个这样的对象:
{% if user == obj.con_id %}