Prepopulate template fields from a form.

I have two models – UserProfile and Address. UserProfile has a foreign key to Address. I have a form for both models using a ModelForm each with a prefix, ‘profile’ and ‘account’ respectively. My view code is as follows:

def UpdateProfileView(request):

if request.method == 'POST':
    
    profile_form = UserProfileUpdateForm(request.POST, prefix='profile')
    address_form = AddressForm(request.POST, prefix='address')
    

    
    if all(profile_form.is_valid(), address_form.is_valid):
        profile_form.save()
        address_form.save()
        messages.success(request, "Your profile has been updated")
        context = {
            "profile_form" : profile_form,
            "address_form" : address_form
        }
        return render(request, "registration/update.html", context)

else:
    profile_form = UserProfileUpdateForm(prefix='profile')
    address_form = AddressForm(prefix='address')    
    context = {
        "profile_form" : profile_form,
        "address_form" : address_form
        }
    return render(request, "registration/update.html", context)

how can i do this? i know i need to somehow access the user instance but can’t figure it out.

The currently-logged on user is accessible on the request object as request.user.

You then populate the forms with the model instances by using the instance attribute when you create the instances of the form. (You need to use the instance in both cases - GET and POST.)

What do you want?
Are you saying you want the form to be pre-filled, or are you saying you don’t want the form to be pre-filled?