1

我得到:

ImportError: cannot import name Image (from image_blob.py)

请帮助我,谢谢:s

我的代码:

图像.py:

from google.appengine.ext import db
from app.models.item import Item

class Image(Item):
    # imports
    from app.models.image_blob import ImageBlob
    #from app.models.user import User
    #from list_user import ListUser # is needed in order to have the references

    # references
    #uploaded_by_user = db.ReferenceProperty(User, required = True)
    large_image = db.ReferenceProperty(ImageBlob, required = True)
    small_image = db.ReferenceProperty(ImageBlob, required = True)

    # image info
    title = db.StringProperty(required = True)
    description = db.StringProperty(required = False)

    # metadata


    # relations

图像块:

from google.appengine.ext import db


class ImageBlob(db.Model):
    from app.models.image import Image

    data = db.BlobProperty(required = True)
    image = db.ReferenceProperty(Image, required = True)
4

1 回答 1

2

您正在尝试从处理image_blob.py整个文件之前导入image.py。在from app.models.item import Item发生时,class Image尚未定义,因此还不能导入(必须在实际定义符号之前处理整个类定义)。

有一个简单的解决方案:不要imageImageBlob. AppEngine 的模型会自动为您定义一个向后引用,因此当您ImageBlob将尺寸 1)。ImageImageBlobImage

于 2010-10-31T21:18:33.380 回答