(token_name, denied_template=None)
return decorator
returns a decorator that checks if the security token in the 'token' GET
    parameter matches the requires token for the resource. The protected
    resource is indicated by
    * the username parameter passed to the decorated function
    * token_name passed to this method

    The decorated method is returned, if
    * no token is required for the resource
    * the token in the 'token' GET parameter matches the required token

    If the passed token does not match
    * the denied_template is rendered and returned if given
    * HttpResponseForbidden is returned, if denied_template is not given
returns a decorator that checks if the security token in the 'token' GET
    parameter matches the requires token for the resource. The protected
    resource is indicated by
    * the username parameter passed to the decorated function
    * token_name passed to this method
returns a decorator that checks if the security token in the token GET parameter matches the requires token for the resource . The protected resource is indicated by * the username parameter passed to the decorated function * token_name passed to this method
def requires_token(token_name, denied_template=None):
    """
    returns a decorator that checks if the security token in the 'token' GET
    parameter matches the requires token for the resource. The protected
    resource is indicated by
    * the username parameter passed to the decorated function
    * token_name passed to this method

    The decorated method is returned, if
    * no token is required for the resource
    * the token in the 'token' GET parameter matches the required token

    If the passed token does not match
    * the denied_template is rendered and returned if given
    * HttpResponseForbidden is returned, if denied_template is not given
    """

    def decorator(fn):
        @wraps(fn)
        def tmp(request, username, *args, **kwargs):

            User = get_user_model()
            user = get_object_or_404(User, username=username)
            token = user.profile.get_token(token_name)
            u_token = request.GET.get("token", "")

            if token == "" or token == u_token:
                return fn(request, username, *args, **kwargs)

            else:
                if denied_template:
                    return render(request, denied_template, {"other_user": user})

                else:
                    return HttpResponseForbidden()

        return tmp

    return decorator
def requires_token ( token_name , denied_template = None ) : def decorator ( fn ) : @ wraps ( fn ) def tmp ( request , username , * args , * * kwargs ) : User = get_user_model ( ) user = get_object_or_404 ( User , username = username ) token = user . profile . get_token ( token_name ) u_token = request . GET . get ( "token" , "" ) if token == "" or token == u_token : return fn ( request , username , * args , * * kwargs ) else : if denied_template : return render ( request , denied_template , { "other_user" : user } ) else : return HttpResponseForbidden ( ) return tmp return decorator