0

I have a django template in which a logged in user can check his/her account balance. The balance is obtained in the django template through a form labelled as 'form0'. Now I want to display this user balance through an alertbox. Given below are the relevant files:

HTML:

{% extends "base.html" %}
{% load bootstrap4 %}
{% block content %}
<form action="/profiles/userLogin/" method="POST">
    <button  class="material-icons floating-btnz" name="form0" onClick='showMessage()></button>
</form>

<script>
function showMessage(){
    alert("Your balance is " + balance);
}
</script>
{% endblock %}

views.py:

if request.method=="POST":
    if 'form0' in request.POST:
        x = employee.objects.get(name = request.user)
        y = x.balance
        return render(request, 'profiles/userLogin.html', {'balance': y})

models.py:

class employee(models.Model):
    name = models.OneToOneField(User, on_delete=models.CASCADE)
    id = models.CharField(max_length=20, primary_key=True)
    balance = models.IntegerField(default=0)

How can I implement this requirement in my system? Any help is appreciated.

DHRUV KAUSHAL
  • 127
  • 10

0 Answers0