名称“订单”未定义

时间:2012-05-14 14:24:09

标签: python django scope satchmo

我有这个错误

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

以供将来参考。

我认为您忘记了导入订单类