ImageField 未定义

ImageField is not defined

我正在使用 Django 构建个人摄影网站。我正在研究 models.py。我的应用名为 "photoViewer",网站名为 "photoSite"。但是,当我 运行 进行迁移时,我得到:

NameError: name 'ImageField' is not defined

我在 "photoSite\photoViewer\static\photoViewer\images" 本地存储了 3 张图像,我想在我完成的网站上显示它们。

Models.py:

from django.db import models

# Create your models here.
class Photo (models.Model):
    photo_title = models.CharField(max_length=200)
    photo_img = ImageField(upload_to = "images/") #Error here
    def __str__(self):              # __unicode__ on Python 2
        return self.photo_title
class Album (models.Model):
    photos= models.ManyToManyField(Photo)
    album_title = models.CharField(max_length=200)

    def __str__(self):              # __unicode__ on Python 2
        return self.album_title

settings.py:

...
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static').replace('\','/')
STATIC_URL = '/static/'
...

看起来你有语法问题...

photo_img = ImageField(upload_to = "images/")

应该是...

photo_img = models.ImageField(upload_to = "images/")