Why does Django show an error for trying to access a user object?

I don’t understand what’s the syntax error

Doesn’t work when I type user = request.user either

Syntax error means there’s something not following rules of the python language. It doesn’t necessarily need to be related to the place where syntax error is detected. In here - it’s very likely error is in the previous line.

Without seeing the code it’s impossible to say for sure what is wrong.

1 Like

It is too difficult to give a conclusion with limited information.
Having said that, I think this documentation is very related with your problem.
Instead of trying to access a user object, You can try to create a new user object with the helper function:

I am not sure about the cause of syntax error, but in the past I had seen a related case, in which someone confused between request , which is a module imported at global level from django.http , and self.request, an attribute of the view instance.
Hope this helps

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.