decorators.py 文件源码

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

项目:open-synthesis 作者: twschiller 项目源码 文件源码
def cache_on_auth(timeout):
    """Cache the response based on whether or not the user is authenticated.

    Do NOT use on views that include user-specific information, e.g., CSRF tokens.
    """
    # https://stackoverflow.com/questions/11661503/django-caching-for-authenticated-users-only
    def _decorator(view_func):
        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            key_prefix = "_auth_%s_" % request.user.is_authenticated()
            return cache_page(timeout, key_prefix=key_prefix)(view_func)(request, *args, **kwargs)
        return _wrapped_view
    return _decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号