Django视图(对象创建命令:缩进错误)

时间:2018-11-04 16:06:49

标签: python django braintree

即使我重新检查并缩进了所有内容,我仍然在下面收到此错误。下面的代码行有什么问题吗?

order_details = Order.objects.create()

TabError:缩进中的制表符和空格使用不一致

def cart_detail(request, total=0, cart_items = None):
    if request.method == 'POST':
        try:
            result = transact({
                'amount': braintree_total,
                'payment_method_nonce': request.POST['payment_method_nonce'],
                'options': {
                    "submit_for_settlement": True
                }
            })

            if result.is_success or result.transaction:
                try:
                    order_details = Order.objects.create(
                            token = client_token,
                            total = braintree_total
                        )
                    order_details.save()
                    for order_item in cart_items:
                        oi = OrderItem.objects.create(
                                product = order_item.product.name,
                                service = order_item.service.name,
                                price = order_item.product.price,
                                order = order_details
                            )
                        oi.save()

                    try:
                        '''Calling the sendEmail function'''
                        sendEmail(order_details.id)
                        print('The order email has been sent to the customer.')
                    except IOError as e:
                        return e
                    return redirect('order:thanks', order_details.id)

                except ObjectDoesNotExist:
                    pass
        except ObjectDoesNotExist: #not sure if this line is correct
            return HttpResponse('FAIL')

    context = {
        'cart_items': cart_items,
        'total': total,
        'client_token': client_token 
    }

    return render(request, 'cart.html', context)

0 个答案:

没有答案