0

我在理解“导入”时遇到了一些麻烦

这段代码可以正常工作。一世

from checkout import create_order

# Create your views here.
def checkout(request):
    if request.method == 'POST':


        create_order(request)

        return HttpResponseRedirect('/menu/')


    return render_to_response("payment_form.html",locals(), context_instance=RequestContext(request))

但由于某种原因,这段代码给了我错误:(函数'对象没有属性'create_order')

import checkout

# Create your views here.
def checkout(request):
    if request.method == 'POST':


        checkout.create_order(request)

        return HttpResponseRedirect('/menu/')


    return render_to_response("payment_form.html",locals(), context_instance=RequestContext(request))

它不应该一样吗?

这是创建订单功能

from cart import cart
from models import Order, OrderItem
from django.core import urlresolvers
import urllib


def create_order(request): 
    order = Order()

    order.user = request.user
    order.status = Order.SUBMITTED

    #have this fix this
    order.time = 7

    order.save()

    # if the order save succeeded 
    if order.pk:
        cart_items = cart.get_cart_items(request) 
        for ci in cart_items:
            # create order item for each cart item 
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price # now using @property oi.product = ci.product
            oi.product = ci.product
            oi.save()

        # all set, empty cart
        cart.empty_cart(request) 

    # return the new order object 
    return order

这是我的文件的 img 在此处输入图像描述

4

1 回答 1

3

这是你的问题:

import checkout

# Create your views here.
def checkout(request):

您的函数与模块具有相同的名称,因此这是尝试在函数上调用函数checkout

checkout.create_order(request)
于 2012-08-24T20:53:08.527 回答