我将一些数据传递给我的模板(“appointments.html”),如下所示:
今天的约会
预约号:84218332 预约时间:2019-10-18T01:00:00
- 到达的
预约号:84218332 预约时间:2019-10-18T22:05:00
- 到达的
<h1>Appointments today</h1>
{% for p in appointment %}
<tr>
<td>Appointment ID : {{ p.patient }} Scheduled Time: {{p.scheduled_time}}</td>
<td>
<form action="{{ p.id }}" method="post">
{% csrf_token %}
<input type="hidden" name="appid" value="{{ p.id }}">
<input type="submit" value="Arrived" class="btn btn-primary">
</form>
</td>
</tr>
{% endfor %}
我想通过单击“到达”按钮来调用views.py 中的另一个视图,该按钮取回作为值传递的p.id,以进一步将其用于其他目的。
urls.py:
url(r'^appointment/<int:appid>/$', views.arrived, name='arrived')
视图.py
def arrived(request, appid):
if request.method == 'POST':
print(appid)
错误 :
Using the URLconf defined in drchrono.urls, Django tried these URL patterns, in this order:
^setup/$ [name='setup']
^welcome/$ [name='welcome']
^appointment/$ [name='appointment']
^appointment/<int:appid>/$ [name='arrived']
^schedule/$ [name='schedule']
^patient_checkin/$ [name='checkin']
^update_info/$ [name='update']
^admin/
^login/(?P<backend>[^/]+)/$ [name='begin']
^complete/(?P<backend>[^/]+)/$ [name='complete']
^disconnect/(?P<backend>[^/]+)/$ [name='disconnect']
^disconnect/(?P<backend>[^/]+)/(?P<association_id>\d+)/$ [name='disconnect_individual']
The current path, appointment/131848814, didn't match any of these.
我该如何解决这个问题,我到底错过了什么?
编辑:改变了我的方法。认为这更容易。