Is there any way to add custom attributes to current_user? Other than adding model relationships. For example, each of my users belongs to a company. I want to have something like current_user.company_name be available. I’ve tried reading the documentation, but could not find anything about this.
Thanks for any help.
I don’t have flask available to try it, but have you tried just adding
your own attributes to current_user?
What happens if you run this?
current_user.company_name = "Acme Ltd"
By default, most non-builtin Python objects accept arbitrary attributes.
If current_user does not, it is because the Flask designers have
specifically taken steps to prevent it.
Yes, I have tried that. It works for 1 request, but the next time the user is loaded, that attribute is either gone or the value is lost. I tried adding an attribute in the load user function, but this leads to a recursion problem. I want to be able to set the attribute just once, and then it will always be available.