我在理解“导入”时遇到了一些麻烦
这段代码可以正常工作。一世
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