当前位置:网站首页>Flask blog practice - realize personal center and authority management

Flask blog practice - realize personal center and authority management

2022-06-25 10:14:00 Light programming

So far in the tutorial, we have already finished the content 95%, Learning is like sailing against the current , move forward , or you 'll fall behind , This is especially true of Internet technology , So no matter what you learn, you should write 、 Think about it 、 To practice , Often things that seem very simple can't be done by themselves , Either lack of programming thinking or weak foundation , Whatever the reason , You can make up for it by practicing hard , Knowledge sharing is also a means of learning , I wish every student who sees this tutorial and can stick to it here have a successful study !

Realize the authority management

The well-known management permission model in the management background generally follows RABC Model to implement , If this part is expanded , That's like another tutorial , So our blog is very simple , It is the simplest way to manage permissions , It also provides you with a flask An idea of permission configuration !

Our users are currently classified into two categories , One is super administrator , One is ordinary users , Have all permissions for Super Administrator , You can visit any of the websites url, Then ordinary users are the users who register and log in , In addition to the public url Only authorized url, This permission is based on url To achieve , The control is rough , But enough to say !

stay app/auth/views/auth.py Medium load_logged_in_user Method , The code is as follows :

@bp.before_app_request
def load_logged_in_user():
    #  Before every request session View in user_id To get users 

    #  Registered users are those that non administrator users are allowed to view after logging in url
    urls = ['/auth/']

    user_id = session.get('user_id')
    if user_id is None:
        g.user = None
    
原网站

版权声明
本文为[Light programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250918142163.html