我在Django中有一个函数,需要为用户创建一个确认弹出窗口...该函数包含许多条件,我需要在不对代码进行大量更改的情况下创建此弹出窗口。花了很多时间,我找到了按钮的“返回确认” ..但是我无法更改弹出窗口的设计。
函数是:
def start(request):
user = request.user
ctx = {
'id-1': request.GET.get('id-1'),
'start_order': StartOrder.objects.filter(
user=user, status='ru'),
}
initial = {
'email': user.email or '',
'password': user.password or '',
}
初始表格应出现在确认弹出窗口之前
if request.method == 'GET':
ctx['form'] = Form(initial=initial)
ctx['can_create'] = user.can_create()
return render(request, 'orders.html', ctx)
确认弹出窗口后:
if request.GET.has_key('id-1'):
test = get_object_or_404(Test, id=request.GET.get('id-1'))
form = Form(request.POST, request=request)
if form.is_valid():
if not user.can_create_order():
return Http404()
ctx['form'] = Form(initial=initial)
ctx['can_create'] = user.can_create_order()
user.email = request.POST.get('email')
user.password = request.POST.get('password')
user.save()
if request.GET.has_key('id-1'):
send_order(test)
ctx['started'] = True
return render(request, 'orders.html', ctx)
orders.html:
{% if id-1 %}
<form class="user-form " method='post'>
{% csrf_token %}
<div class="errors">
{{form.non_field_errors}}
</div>
<div class="form-group">
{% for field in form %}
{{field}}
{{field.errors}}
{% endfor %}
</div>
单击后弹出窗口应出现的按钮:
<input type='submit' value='Start Automated Order' onclick="return confirm('Are you sure you want to continue?');">
</form>
{% else %}
{% endif %}