本flask源码分析不间断更新

而且我分析的源码全是我个人觉得是很漂亮的

 

1 flask-login

1.1 flask.ext.login.login_required(func),下面是它的文档的官方源码

 1 def login_required(func):
 2     '''
 3     If you decorate a view with this, it will ensure that the current user is
 4     logged in and authenticated before calling the actual view. (If they are
 5     not, it calls the :attr:`LoginManager.unauthorized` callback.) For
 6     example::
 7 
 8         @app.route('/post')
 9         @login_required
10         def post():
11             pass
12 
13     If there are only certain times you need to require that your user is
14     logged in, you can do so with::
15 
16         if not current_user.is_authenticated:
17             return current_app.login_manager.unauthorized()
18 
19     ...which is essentially the code that this function adds to your views.
20 
21     It can be convenient to globally turn off authentication when unit testing.
22     To enable this, if the application configuration variable `LOGIN_DISABLED`
23     is set to `True`, this decorator will be ignored.
24 
25     :param func: The view function to decorate.
26     :type func: function
27     '''
28     @wraps(func)
29     def decorated_view(*args, **kwargs):
30         if current_app.login_manager._login_disabled:
31             return func(*args, **kwargs)
32         elif not current_user.is_authenticated:
33             return current_app.login_manager.unauthorized()
34         return func(*args, **kwargs)
35     return decorated_view
View Code

相关文章:

  • 2019-11-03
  • 2021-04-26
  • 2022-12-23
  • 2020-03-19
  • 2021-09-15
  • 2021-12-03
  • 2021-08-17
  • 2022-03-07
猜你喜欢
  • 2021-06-24
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2021-10-11
  • 2019-03-27
相关资源
相似解决方案