标签:ati rom miss short href utils mis redirect elf
import re from django.utils.deprecation import MiddlewareMixin from django.shortcuts import HttpResponse,redirect from app01.models import Permission class PermissionMiddleWare(MiddlewareMixin): def process_request(self,request): current_path = request.path for reg in [‘/login/‘,‘/admin/‘]: ret=re.search(reg,current_path) if ret: return None user_id=request.session.get(‘user_id‘) if not user_id: return redirect(‘/login/‘) permission_list=request.session.get(‘permission_list‘) request.breadcrumb = [] for item in permission_list: reg=‘^%s$‘%item["url"] ret=re.search(reg,current_path) if ret: show_id=item["pid"] or item["id"] request.show_id = show_id if item["pid"]: pPermission=Permission.objects.filter(pk=item["pid"]).first() request.breadcrumb.extend( [ { ‘title‘:pPermission.title, ‘url‘:pPermission.url }, { ‘title‘: item[‘title‘], ‘url‘: item[‘url‘] } ] ) else: request.breadcrumb.append( { ‘title‘:item[‘title‘], ‘url‘:item[‘url‘] } ) return None return HttpResponse(‘无权限访问‘)
<ol class="breadcrumb"> {% for foo in request.breadcrumb %} <li><a href="{{ foo.url }}">{{ foo.title }}</a></li>/ {% endfor %} </ol>
标签:ati rom miss short href utils mis redirect elf
原文地址:https://www.cnblogs.com/xuqidong/p/12601799.html