面包屑路径导航
Posted xuqidong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面包屑路径导航相关的知识,希望对你有一定的参考价值。
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>
以上是关于面包屑路径导航的主要内容,如果未能解决你的问题,请参考以下文章
Fastadmin CMS伪静态时面包屑导航网址不正确的应急处理