Skip to content
Advertisement

Python decorator – Check if user is admin

I am creating simple API using flask, and I want to check if user which is trying to access is admin. This is function which should decide if user is admin or not

JavaScript

And this is endpoint

JavaScript

I am getting this error

JavaScript

I don’t know where is the problem, I did this according this documentation. Could someone help me how to solve this issue?

Advertisement

Answer

Is the indentation in your post what is actually in your code, because it is indented wrong. Here is an example of an authentication check (not an admin check), but you can see how the indentation should look. You are also missing the decorator on wraps(f).

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement