我有这个型号:
projectDirPath = path.dirname(path.dirname(__file__))
storeImageDir = FileSystemStorage(location=projectDirPath + '/couponRestApiApp/stores')
class stores(models.Model):
""" This is the store model """
storeName = models.CharField(max_length=15) # Store Name
storeDescription = models.TextField() # Store Description
storeURL = models.URLField() # Store URL
storePopularityNumber = models.IntegerField(max_length=1) # Store Popularity Number
storeImage = models.ImageField(upload_to="images",storage=storeImageDir) # Store Image
storeSlug = models.CharField(max_length=400) # This is the text you see in the URL
createdAt = models.DateTimeField(auto_now_add=True) # Time at which store is created
updatedAt = models.DateTimeField(auto_now=True) # Time at which store is updated
storeTags = models.ManyToManyField(tags) # All the tags associated with the store
def __unicode__(self):
return unicode(self.storeName)
def StoreTags(self):
return '\n'.join([s.tag for s in self.storeTags.all()])
def StoreImage(self):
return '<img src="%s" height="150"/>' % (self.storeImage)
StoreImage.allow_tags = True
但是图像没有加载到管理页面上,并且图像URL是:http://localhost:8000/admin/couponRestApiApp/stores/static/mcDonalds.jpg/
正在显示,但正确的路径应为:/home/vaibhav/TRAC/coupon-rest-api/couponRestApi/couponRestApiApp/stores/static/mcDonalds.jpg/
图像应该存储在哪里,以便它们将显示在Django管理页面上
在设置中正确定义}。在
MEDIA_ROOT
和{在设置.py
在模型.py
^{2}$在网址.py
尝试使用上述代码。在
对评论中提出的问题的回答:
“s”将添加到模型名称中,因为将有多个模型实例。要消除它,请为模型定义
verbose_name
。在根据Django文档,对于Django 1.11及更高版本,您需要重写:
网址.py
相关问题 更多 >
编程相关推荐