Hi, in my project with BMI calculator (with database) the part of my code in template bmi.html looks like this:
<div class="form-style">
<form method="post">
{% csrf_token %}
<h2>BMI Calculator</h2>
<hr>
{% if user.is_authenticated %}
<button type="button" class="btn btn-info" style="color:white">CLICK IF YOU WANT TO FILL OUT THE FORM WITH LAST SAVED DATA</button>
{% endif %}
<hr>
<p>{{ form.height.label }}{{ form.height }}<br></p>
<p>{{ form.weight.label }}{{ form.weight }}<br></p>
<p>{{ form.gender.label }}{{ form.gender }}<br></p>
<br>
<input type="submit" class="btn btn-primary my-btn" value="Calculate" />
<span/>
<input type="reset" class="btn btn-danger my-btn" value="Clear" />
<br>
</form>
</div>
If user presses the btn-info button, I want to fill out the form with the last data saved in the user’s account in models. How can I accomplish it? Do I need to use AJAX?