我有一个调用多个视图的模板。但是由于某种原因,人们正在调用相同的观点。我无法弄清楚。
模板:schedule.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Schedule Page</title>
</head>
<body>
<h1>Today's Schedule </h1>
<b>Scheduled Appointments:</b>
<div>
{% for p in schedule %}
<p> {{p.id}} {{p.name}} {{p.surname}} {{p.appointment_time }} </p>
{% if p.status == "Arrived" %}
<p>Patient Arrived</p>
<!-- <button>See Patient</button> -->
<form action="{% url 'see_patient' p.id %}" method="post">
{% csrf_token %}
<input type="hidden" name="appid" value="{{ p.id }}">
<input type="submit" value="See Patient" class="btn btn-primary">
</form>
{% elif p.status == 'In Session' %}
<p>In Progress</p>
<form action="{% url 'complete' p.id %}" method="post">
{% csrf_token %}
<input type="hidden" name="app_id" value="{{ p.id }}">
<input type="submit" value="Complete" class="btn btn-primary">
</form>
{% elif p.status == 'Complete' %}
<p>Completed</p>
{% else %}
<p>{{p.status}}</p>
{% endif %}
{% endfor %}
</div>
</br>
</body>
</html>
views.py:
def see_patient(request, appid):
print("See Patient", appid)
app = CheckAppointments()
app.update_appointment_status(appid, {'status' : 'In Session'})
appointment_obj = Appointments.objects.get(appointment_id = appid)
appointment_obj.status = "In Session"
update_wait_time(request)
return redirect('/schedule/')
def appointment_complete(request, app_id):
print("Complete:", app_id)
app = CheckAppointments()
app.update_appointment_status(app_id, {'status' : 'Complete'})
appointment_obj = Appointments.objects.get(appointment_id = app_id)
appointment_obj.status = "Complete"
appointment_obj.save()
resume_time(request)
return redirect('/schedule/')
urls.py
url(r'^schedule/$', views.ScheduledAppointments.as_view(), name='schedule'),
url(r'^schedule/(?P<appid>\d+)/$', views.see_patient, name='see_patient'),
url(r'^schedule/(?P<app_id>\d+)/$', views.appointment_complete, name='complete'),
当我单击“完成”时,POST请求仍被发送到see_ Patient视图,而不是约会完成。