【发布时间】:2017-02-09 14:21:53
【问题描述】:
基本上,我目前正在尝试解决这样一个事实,即您必须在表单提交后执行 HttpResponseRedirect 以避免在页面刷新时重复提交。
所以我希望我的表单的提交按钮触发另一个视图,而不是提交当前视图。这是我的html: (我已经把表格拿出来了,因为有很多代码可以水平渲染表格)
<form id= "time-form" method = 'POST' action='' class="dynamic-form" enctype="multipart/form-data">{% csrf_token %}
<div id="formset-container" class = "formset-container">
<table>
<--form is in here-->
</table>
<ul>{{ newtime_formset.errors }}</ul>
</div>
</br>
<div>
<input type = "submit" id = "save" action="{% url 'tande:create_time' %}" value = "Save Timesheet">
</div>
所以我希望提交按钮执行 create_time 视图。我们目前处于一个名为时间表的视图中。但它根本没有进入 create_time 视图,它只是停留在当前视图中。
def create_time(request):
#below isn't printing
print "create_time view"
#save the form in here
return HttpResponseRedirect('timesheet')
两个视图的网址:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^(?P<timesheet_id>[0-9]+)/person/timesheet/$', views.timesheet, name='timesheet' ),
url(r'^create_time/$', views.create_time, name='create_time' ),
]
所以我想将时间表保存在 create_time 中,然后返回到时间表以避免重定向....我认为这是有道理的....:S
谢谢
【问题讨论】: