首页 技术 正文
技术 2022年11月15日
0 收藏 855 点赞 3,902 浏览 2079 个字

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

在permission中加入

name=models.CharField(max_length=32, verbose_name=’url别名’,default=””)

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

左后注入session中

request.session["permission_names"] = permission_names3.在标签处写入判断
 {% extends 'web/layout.html' %} {% block content %}     <div class="luffy-container">
<div class="btn-group" style="margin: 5px 0">
{% load web %}
{% if "customer_add"|has_permission:request %}
<a class="btn btn-default" href="/customer/add/" rel="external nofollow" >
<i class="fa fa-plus-square" aria-hidden="true"></i> 添加客户
</a>
{% endif %} </div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>客户姓名</th>
<th>年龄</th>
<th>邮箱</th>
<th>公司</th> {% if "customer_edit"|has_permission:request%}
<th>编辑</th>
{% endif %}
{% if "customer_del"|has_permission:request %}
<th>删除</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for row in data_list %}
<tr>
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>{{ row.age }}</td>
<td>{{ row.email }}</td>
<td>{{ row.company }}</td> {% if "customer_edit"|has_permission:request %}
<td>
<a style="color: #333333;" href="/customer/edit/{{ row.id }}/" rel="external nofollow" >
<i class="fa fa-edit" aria-hidden="true"></i>
</a>
</td>
{% endif %} {% if "customer_del"|has_permission:request %}
<td>
<a style="color: #d9534f;" href="/customer/del/{{ row.id }}/" rel="external nofollow" >
<i class="fa fa-trash-o"></i>
</a>
</td>
{% endif %} </tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

customer_list

4.引用的web

 from django.utils.safestring import mark_safe
from django.template import Library
import re
register =Library() @register.inclusion_tag("rbac/menu.html")
def get_menu_styles(request):
permission_menu_dict = request.session.get("permission_menu_dict")
print("permission_menu_dict",permission_menu_dict) for val in permission_menu_dict.values():
for item in val["children"]:
val["class"]="hide" ret=re.search("^{}$".format(item["url"]),request.path)
if ret:
val["class"] = "" return {"permission_menu_dict":permission_menu_dict} @register.filter
def has_permission(btn_url,request):
permission_names = request.session.get("permission_names") return btn_url in permission_names ''' {
1:{
"title":"信息管理",
"icon":"",
"children":[
{
"title":"客户列表",
"url":"",
}
] }, 2:{
"title":"财务管理",
"icon":"",
"children":[
{
"title":"缴费列表",
"url":"",
},
] }, } '''

web

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295