decorators.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:nrp 作者: django-rea 项目源码 文件源码
def login_required(func=None, redirect_field_name="next", login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting
    to the log in page if necessary.
    """
    def decorator(view_func):
        @functools.wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            if request.user.is_authenticated():
                return view_func(request, *args, **kwargs)
            return handle_redirect_to_login(
                request,
                redirect_field_name=redirect_field_name,
                login_url=login_url
            )
        return _wrapped_view
    if func:
        return decorator(func)
    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号