gpt4 book ai didi

python - ImageField 未定义

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:31 31 4
gpt4 key购买 nike

我正在使用 Django 构建个人摄影网站。我正在处理 models.py。我的应用名为“photoViewer”,网站名为“photoSite”。但是,当我运行 makemigrations 时,我得到:

NameError: 名称“ImageField”未定义

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

模型.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

设置.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/")

关于python - ImageField 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28003371/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com