S
S
sportik1742021-12-24 19:15:43
Python
sportik174, 2021-12-24 19:15:43

How to write custom decorator in Django views?

Good afternoon!
There is a code that is used to check user authorization (I know that there is a standard functionality, but it needs to be custom)

def decorator_login_check(func):
    def wrapper(request):
        try:
            user = User.objects.get(id=request.session['loged_user'])
        except Exception as ex:
            return redirect('auth_login')
        func(request)
    return wrapper


@decorator_login_check
def index(request):
    """ Главная страница """
    user = User.objects.get(id=request.session['loged_user'])
    context = {
        'user': user
    }
    return render(request, 'main/index.html', context)


It gives the following error:
61c5f21eb3dfa799639988.png

What did I write wrong? help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-24
@sportik174

return func(request)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question