Answer the question
In order to leave comments, you need to log in
How to get the ID of the currently logged in user?
For authentication, I use flask_login
such a problem that you need to get the user id in the post method, for this, as I understand it, the method needs to be decorated with @login_required
to get access to the current_user, but the decorator apparently does not work for post methods and gives an error.
In the get methods, I can access the data of the current user. Also in the post method, if I check if the user is authorized, then False
.
What are the solutions?
class Authenticate(MethodView):
def post(self):
...some code
login_user(user, remember=True)
g.user = current_user.id
class User(MethodView):
def post(view):
# not working
print(current_user.id)
print(g.user)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question