当前位置:网站首页>Flask博客实战 - 实现个人中心及权限管理
Flask博客实战 - 实现个人中心及权限管理
2022-06-25 09:38:00 【轻编程】
教程到这里我们的内容就已经过了95%,学习如逆水行舟,不进则退,互联网技术尤其如此,所以不论学习任何东西都要去写、去思考、去实践,往往看起来非常简单的东西反而自己却无从下手,不是缺乏编程思维就是基础不牢固,无论是那一个原因,通过勤奋不辍的练习都能弥补,知识的分享也是一种学习的手段,祝愿每个看到此教程并且能坚持到这里的同学学有所成!
实现权限管理
在管理后台中比较有名的管理权限模型一般遵循RABC模型去实现,如果这部分内容展开讲的话,那堪比另外一个教程了,那么我们的博客非常简单,就以最简单的方式实现权限的管理,也给大家提供了一个flask权限配置的一个思路!
我们的用户目前就分类两类,一类是超级管理员,一类是普通用户,对于超级管理员拥有所有权限,可以访问网站的任何url,那么普通用户也就是注册登录的用户,则除了公开的url外只能访问授权的url,这个权限根据url去实现,控制的比较粗糙,但足以说明问题!
在app/auth/views/auth.py中的load_logged_in_user方法中注入权限标识,代码如下:
@bp.before_app_request
def load_logged_in_user():
# 每个请求之前都会去session中查看user_id来获取用户
# 注册用户即非管理员用户允许登录后查看的url
urls = ['/auth/']
user_id = session.get('user_id')
if user_id is None:
g.user = None
边栏推荐
- Force buckle -104 Maximum depth of binary tree
- Fluent: target support file /pods runner / pods runner frameworks Sh: permission denied - stack overflow
- 字符串 最长公共前缀
- How to apply for a widget on wechat how to get a widget on wechat
- manhattan_slam环境配置
- Flutter replaces the default icon of Gaud positioning
- How to make small programs on wechat? How to make small programs on wechat
- Kotlin advanced set
- MySQL创建给出语句
- Jetpack compose layout (II) - material components and layout
猜你喜欢

独步武林,架构选型手册(包含 PDF)

How to build a wechat applet? How to open an applet?

Wearable devices may reveal personal privacy

Flutter dialog: cupertinoalertdialog

8. Intelligent transportation project (1)

Minio基本使用与原理

汇付国际为跨境电商赋能:做合规的跨境支付平台!

Methodchannel of flutter

2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?

Mengyou Technology: tiktok live broadcast with goods elements hot topics retention skills shaping image highlight selling points
随机推荐
Remittance international empowers cross-border e-commerce: to be a compliant cross-border payment platform!
ShardingSphere-Proxy 4.1 分库分表
Armbian version name comparison
Neat Syntax Design of an ETL Language (Part 2)
Wearable devices may reveal personal privacy
Processing picture class library
An auxiliary MVP architecture project quick development library -mvpfastdagger
i++ 和 ++i的真正区别
[wechat applet full stack development course] course directory (mpvue+koa2+mysql)
Neat Syntax Design of an ETL Language (Part 2)
How to "transform" small and micro businesses (I)?
C语言刷题随记 —— 猴子吃桃
Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?
Vscode attempted to write the procedure to a pipeline that does not exist
Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
‘Flutter/Flutter. h‘ file not found
View. post VS Handler. Differences and usage scenarios of post
Exception: gradle task assemblydebug failed with exit code 1
Experience in writing C