视图customer_reg.views.Set_Checkout_Attributes没有返回HttpResponse对象

时间:2012-09-18 05:48:39

标签: django django-templates django-views

我正在创建一个应用程序,在用户注册后,他会引用一个页面,在该页面上,他可以单击链接以填充另一个订单详细信息。 当我点击该链接后,视图处于活动状态

def Checkout_Attributes(request):

    check_form = Check_Attribute_Form()
    context={'check_form':check_form}
    return render_to_response('checkout.html',context,context_instance=RequestContext(request))

并且在提交视图后的表单是活动的

def Set_Checkout_Attributes(request):

    #if request.user.is_authenticated():
        #return HttpResponseRedirect('/checkout/')

    if request.method == 'POST':
        check_form = Check_Attribute_Form(request.POST)
            if check_form.is_valid():
            customer_check=Customer_check_attributes(billing_add=check_form.cleaned_data['billing_add'],shipping_add=check_form['shipping_add'],payment_method=check_form['payment_method'],shipping_method=check_form['shipping_method'],reward_points=check_form['reward_points'])
            customer_check.save()
            return render_to_response('sucess.html')
    else:
        check_form=Check_Attribute_Form()
        return render_to_response('a.html',{'check_form':check_form} , context_instance=RequestContext(request))  

在此视图中,我收到错误 Set_Checkout_Attributes未返回HttpResponse对象。

当我提交空白表单时,还有一件事就是没有显示验证错误

模板为

<form action="/checkout1/" method="post">
{% csrf_token %}
{% if check_form.errors  %}<h2>Please correct the following fields:</h2>{% endif %}
<div class="register_div">
        {% if check_form.billing_add.errors %}<p class="error">{{ check_form.billing_add.errors }}</p>{% endif %}
    <p><label for="billing_add" {% if check_form.billing_add.errors %} class="error"{% endif %}>Billing Address:</label></p>
    <p>{{ check_form.billing_add }}</p>
</div>
.
.
.
.
.
<p><input type="submit" value="submit" aly="register"/></p>
</form>

1 个答案:

答案 0 :(得分:0)

首先,请为您的变量和视图使用适当的PEP-8名称。

其次,不要在成功时渲染模板 - 重定向到新页面。

最后,考虑一下你的观点的逻辑。当表单无效时会发生什么?在那种情况下返回什么?再看一下文档中的示例,它会准确显示您应该使用的结构。