【发布时间】:2020-12-16 10:46:36
【问题描述】:
我有一个模态表单,单击某些按钮会显示该表单。 当用户填写表单并提交时,我可以保存数据并将用户重定向到索引页面。 如果用户返回上一页,他会看到“旧”表单已经填写,因为页面没有刷新。我能做什么?
这是我的看法:
def calendar(request):
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = ReservationForm(request.POST)
# check whether it's valid:
print('prima del form valid')
if form.is_valid():
print("il form e' valido")
reservation = form.save(commit=False)
reservation.validation_code = get_random_string(length=32)
reservation.delete_code = get_random_string(length=8).upper()
reservation.reservation_confirmed = False
reservation.save()
return redirect('prenotazionicampo:index')
# return render(request, 'prenotazionicampo/index.html')
else:
print(form.errors)
# if a GET (or any other method) we'll create a blank form
else:
form = ReservationForm()
【问题讨论】:
-
“返回”是指用户点击“返回”按钮吗?
-
是的!浏览器的“返回”按钮
标签: python django forms redirect