简体   繁体   English

仅当登录用户是创建 object 的用户时,如何使编辑和取消链接出现? Django

[英]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 asfor循环中,您可以检查是否是创建它的同一用户,如果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.

相关问题 Django:登录链接仅在用户登录时出现 - Django: login link to appear only when a user is logged in 创建用户后,如何将用户与 django model 链接? - How do I link a User with a django model as soon as the User is created? 如何使用Django将一个页面显示给已登录的用户,将另一个页面显示给未登录的用户? - How do I show one page to logged-in user and another to a not-logged in user with Django? 仅当创建的用户位于 Django 中的特定组时,我如何才能使信号运行? - How do I make a signal run only if the user created is on a specific group in Django? 如何让用户编辑/更新 Django 中的 .py 文件? - How do I make the user edit/update the .py file in Django? Python/Django 我如何做到这一点,以便只有对象/帖子的创建者才能看到他们帖子的删除/编辑 function 按钮? - Python/Django How do I make it so that only the creator of an object/post can see a delete/edit function button for their post? 如何在 Django 中获取特定用户的信息(我想获取现在已登录的特定用户的约会历史记录) - how to get information for specific user in Django ( i wanted to get Appointment history for specific user who is now logged in ) 在Django的“登录”内置应用中,当用户已经登录时,如何使它重定向到首页? - In Django's “login” built in app, how do I make it redirect to the home page when the user is already logged in? Maya Python:当在另一个函数中创建对象时,如何在一个函数中调用和编辑该对象的属性? - Maya Python: How do i call on and edit attributes of an object in one function when that object was created in another function? 如何允许用户仅编辑自己创建的对象? - How to allow user to edit only object created by self?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM