I am going a tad crazy here. I keep getting this error: ImportError: No module named models and I am not sure why. Here is what I have found so far...
>>>开发者_Go百科 from django.shortcuts import get_object_or_404, redirect
>>> from mystore.cart import cart
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/Jeff/django/mystore/cart/cart.py", line 3, in <module>
from mystore.cart.models import CartItem
ImportError: No module named models
>>>
I am not sure what's going on with this... line 3 in cart.py is this:
from mystore.cart.models import CartItem
If I try to do: from mystore.cart.models import CartItem it works fine...
Any suggestions?
Almost certainly, you have a circular dependency: mystore.cart.cart
is importing mystore.cart.models
, which in turn is trying to import mystore.cart.cart
.
You should determine if both of those imports are necessary, and if either of them could be moved out of the global scope into a function or method.
Why are you doing from mystore.cart import cart
? That should be just from mystore import cart
.
Very early in the mystore.cart.models an error is occurring that's why nothing in models.py can be imported. The error can be a circular import, a conditional statement that's triggered during runtime but not at the command prompt or is happening inside something else your are importing at the beginning of models.py
You have to put a point before.
bad
from models import *
good
from .models import *
that means that is at the same level.
精彩评论