1.首先需要一个判断用户是否拥有这个权限的name来区分在主页上是否显示标签

在permission中加入

name=models.CharField(max_length=32, verbose_name='url别名',default="")

2.在rabc.py 中加入一个空列表,用来存放关联的permission__name 来区分

左后注入session中

 

request.session["permission_names"] = permission_names



3.

在标签处写入判断

 1 {% extends 'web/layout.html' %}
 2 
 3 {% block content %}
 4 
 5     <div class="luffy-container">
 6         <div class="btn-group" style="margin: 5px 0">
 7             {% load web %}
 8             {% if "customer_add"|has_permission:request %}
 9                  <a class="btn btn-default" href="/customer/add/">
10                     <i class="fa fa-plus-square" aria-hidden="true"></i> 添加客户
11                  </a>
12             {% endif %}
13 
14         </div>
15         <table class="table table-bordered table-hover">
16             <thead>
17             <tr>
18                 <th>ID</th>
19                 <th>客户姓名</th>
20                 <th>年龄</th>
21                 <th>邮箱</th>
22                 <th>公司</th>
23 
24                 {% if "customer_edit"|has_permission:request%}
25                  <th>编辑</th>
26                 {% endif %}
27                 {% if "customer_del"|has_permission:request %}
28                  <th>删除</th>
29                 {% endif %}
30             </tr>
31             </thead>
32             <tbody>
33             {% for row in data_list %}
34                 <tr>
35                     <td>{{ row.id }}</td>
36                     <td>{{ row.name }}</td>
37                     <td>{{ row.age }}</td>
38                     <td>{{ row.email }}</td>
39                     <td>{{ row.company }}</td>
40 
41                         {% if "customer_edit"|has_permission:request  %}
42                                <td>
43                                 <a style="color: #333333;" href="/customer/edit/{{ row.id }}/">
44                                     <i class="fa fa-edit" aria-hidden="true"></i>
45                                 </a>
46                                 </td>
47                         {% endif %}
48 
49                         {% if "customer_del"|has_permission:request  %}
50                                <td>
51                                 <a style="color: #d9534f;" href="/customer/del/{{ row.id }}/">
52                                     <i class="fa fa-trash-o"></i>
53                                 </a>
54                                </td>
55                         {% endif %}
56 
57 
58                 </tr>
59             {% endfor %}
60             </tbody>
61         </table>
62     </div>
63 {% endblock %}

customer_list