I am trying to retrieve an instance's current data to bootstrap form for update. When i use {{user_form.as_p}}
all current data is filled automatically however replace it with bootstrap forms it seems empty. Here is my python and html files:
views.py
def update_profile(request):
if request.method == 'POST':
user_form = RegisterForm(request.POST, instance=request.user)
if user_form.is_valid():
user_form.save()
return redirect('profile')
else:
user_form = RegisterForm(instance=request.user)
return render(request, 'blog/update_profile.html', {
'user_form': user_form,
})
update_profile.html
<form method="post">
{% csrf_token %}
<div class="form-group">
<label for="formGroupExampleInput">Name</label>
<div id="formGroupExampleInput">
<input class="form-control" name="first_name" maxlength="150" autofocus required="" id="id_first_name" type="text" placeholder="First name" >
</div>
...
<div class="form-group">
<button type="submit" class="btn btn-success" id="formGroupExampleInput5">Save changes</button>
</div>
</form>
forms.py
class RegisterForm(UserCreationForm):
email = forms.EmailField(max_length=200, help_text='Required')
class Meta:
model = User
fields = ('first_name', 'last_name', 'username', 'email', 'password1', 'password2')