django - Django从模板的多个视图中调用相同的视图
问题描述
我有一个调用多个视图的模板。但由于某种原因,同样的观点被称为。我无法弄清楚。
模板: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>
视图.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/')
网址.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 视图而不是约会完成。
解决方案
推荐阅读
- python - tf.data.Dataset:如何获取数据集大小(一个纪元中的元素数)?
- delphi - Delphi - 在设计器中显示多行标题
- php - Wordpress - 管理面板上未显示自定义插件
- angular - ngx-markdown 在换行后剪切前 10 个字符
- java - QueryDSL Spring 数据 web 支持与 java.util.Date
- swift - Swift 命令行链接因“重复符号”错误而失败
- database - 在支持分组的内存数据库中
- c# - 在c#中提取json对象到json
- android - 在启动时展开recyclerview的第一项而不触摸它
- apache-kafka - ksql,在表上选择不显示任何内容