In Django, how can I see all the properties of my user?

advertisements

If I do something like:

print request.user.is_authenticated()

Then True is printed. However

print request.user

just prints the username even though 'request.user' is definitely not just a string. How can I get all user properties to be printed to the console?


There are many ways, e.g.:

print dir(request.user)

or (this is probably preferred)

print request.user.__dict__

or (see stalk's extended answer, basically does what __dict__ does)

print ["{0}: {1}".format(field.name, getattr(request.user, field.name)) for field in request.user._meta.fields]

or (if you just want methods)

print [attr for attr in dir(request.user) if callable(attr)]