def check_nickname(funct): def wrapper(request, *args, **kwargs): if request.user.profile.nickname: return funct(request, *args, **kwargs) else: from django.shortcuts import render_to_response from django.template import RequestContext return render_to_response('need_profile.html', RequestContext(request)) return wrapper check_nickname function is a decorator for a function of the Django type, about which we know for sure that the request parameter of a certain type is passed to it. The decorated function is passed to the wrapper which is returned instead of the decorated function. @f1 def func(x): pass # : def func(x): pass func = f1(func) wrapper function returned by the check_nickname decorator is check_nickname . And it is the wrapper receives all the parameters intended for the original function of the view, and on their basis the logic of the following actions is already built.Source: https://habr.com/ru/post/134787/
All Articles