1

HTML form on Django. I want to perform or create web page in which the button performs the action, and in backend I am handling the Django function.

The code of HTML file is:

<form name="bookappointment" class="form" method="POST">
   {% csrf_token %}

                  <br>
                  <input type="hidden", name="selecteddoctornumber" value="{{i.doctornumber}}">
<div class="row">

          <div class="col-md-1"></div>

          <div class="col-md-4">
              <button class="btn approve" name="approvebtn">Approved</button>

          </div>

          <div class="col-md-1"></div>

          <div class="col-md-4">
                  <button class="btn notapprove" name="notapprovebtn">Not Approved</button>
          </div>
               <br>
    </div>
                  <a class="btn cancel" href="requests">Cancel</a>

   <br>
   </form>

and the other side the Django function is:

if request.method == 'POST':

    if request.POST.get('approvebtn'):
        for i in doctor:
            if pendingDoctorNumber == i.contactNumber:
                i.status = 'Approved'

        return redirect('request')

    if request.POST.get('notapprovebtn'):
        for i in doctor:
            if pendingDoctorNumber == i.contactNumber:
                i.status = 'Not Approved'

        return redirect('request')

but its not working any action just get me back to same page

1 Answer 1

1
<form action="{% url 'bookappointment' %}" method="POST">

you have to define bookappointment in your urls.py which redirect to views.py where your function lies with name bookappointment.

Sign up to request clarification or add additional context in comments.

3 Comments

Its not perform the function with your method, Kindly help about it
can you post your urls.py and views.py with function define.
urls.py path('requestApprovalbtn', views.requestApprovalbtn , name = 'requestApprovalbtn'),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.