-1

我有这个错误

Name 'Order' is not defined

在以下条款中:

            try:
                order = Order.objects.from_request(request)
                cart = OrderCart(order)
            except Order.DoesNotExist:
                pass

Order在同一个文件中完全定义并且是model.Model

更具体地说,这是我正在使用的文件: https : //bitbucket.org/chris1610/satchmo/src/a04c87a539f3/satchmo/apps/satchmo_store/shop/models.py,第242行出现异常

为什么会这样?

更新:

这是回溯:

Traceback:
File "/home/evgeniuz/.virtualenvs/port/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/evgeniuz/src/chillifish-pg/lib/payment/views/balance.py" in balance_remaining_order
  30.         template='shop/checkout/balance_remaining.html')
File "/home/evgeniuz/src/chillifish-pg/pg/pgstore/utils.py" in _view
  38.             return view_func(request, *args, **kwargs)
File "/home/evgeniuz/src/chillifish-pg/lib/payment/views/balance.py" in balance_remaining
  66.         'paymentmethod_ct': len(config_value('PAYMENT', 'MODULES'))
File "/home/evgeniuz/.virtualenvs/port/lib/python2.7/site-packages/django/template/context.py" in __init__
  149.             self.update(processor(request))
File "/home/evgeniuz/src/chillifish-pg/lib/satchmo_store/shop/context_processors.py" in settings
  21.     cart = Cart.objects.from_request(request)
File "/home/evgeniuz/src/chillifish-pg/lib/satchmo_store/shop/models.py" in from_request
  237.                 except Order.DoesNotExist:

Exception Type: NameError at /shop/checkout/balance/1/
Exception Value: global name 'Order' is not defined
4

2 回答 2

1

也许我只是遗漏了一些东西,但您指的是 CartManager 在定义之前的 Order 类。直到第 642 行才定义订单。我不太了解 Django 的内部工作原理,但我会尝试将 Order 类移到 CartManager 上方,看看它是否能让你克服这个错误。

于 2012-05-14T15:22:29.373 回答
0

备查。

我想你忘了导入订单类

于 2020-12-07T17:14:37.197 回答