In Django, how do you give forms in forms.py initial values based on information of the logged in user?
I would like to create a form to edit user information. The form's default values will be based on currently registered information of the user logged in. For instance, the phone number field will initially have the user's curr开发者_如何学JAVAent phone number.
I am aware of the "initial" attribute, but form objects in form.py cannot accept the request object as a parameter, so it cannot grab information from the logged in user.
I really appreciate your kind help.
Create an appropriate model form and pass it the model pulled from the database.
精彩评论