Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django:从管理员中的静态文件夹渲染图像_Django - Fatal编程技术网

Django:从管理员中的静态文件夹渲染图像

Django:从管理员中的静态文件夹渲染图像,django,Django,我需要为所有上传到管理员的文件呈现缩略图 我使用Adobe Illustrator的徽标来显示这些文件确实是AI文件 但是,它没有被渲染。在HTML中,我得到: <img src="static/img/admin/adobe_illustrator_file_logo.png" width="200px" height="180px"> 呈现如下: 为什么? class OrderItem(models.Model): order = models.ForeignK

我需要为所有上传到管理员的文件呈现缩略图

我使用Adobe Illustrator的徽标来显示这些文件确实是AI文件

但是,它没有被渲染。在HTML中,我得到:

<img src="static/img/admin/adobe_illustrator_file_logo.png" width="200px" height="180px">

呈现如下:

为什么?

class OrderItem(models.Model):
    order = models.ForeignKey(Order, on_delete=models.CASCADE)
    product = models.CharField(max_length= 200)
    quantity = models.CharField(max_length= 200)
    size = models.CharField(max_length=200)
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name= 'PEN Price')
    file = models.FileField(upload_to='files', blank=True, null=True)
    comment = models.CharField(max_length=200, blank=True, null=True, default='')
    uploaded_at = models.DateTimeField(auto_now_add=True)



    class Meta:
        db_table = "OrderItem"

    def file_thumbnail(self):
        if self.file:
           return mark_safe(u'<img src="%s" width="200px" height="180px" />' % ('static/img/admin/adobe_illustrator_file_logo.png'))
        else:
            pass
类OrderItem(models.Model):
order=models.ForeignKey(order,on_delete=models.CASCADE)
产品=型号.CharField(最大长度=200)
数量=型号.CharField(最大长度=200)
尺寸=型号.字符域(最大长度=200)
price=models.DecimalField(最大位数=10,小数位数=2,详细名称='PEN price')
file=models.FileField(上传到class='files',blank=True,null=True)
comment=models.CharField(max_length=200,blank=True,null=True,default='')
上传的\u at=models.datetime字段(自动\u now\u add=True)
类元:
db_table=“OrderItem”
def文件_缩略图(自身):
如果self.file:
返回mark_safe(u'%('static/img/admin/adobe_illustrator_file_logo.png'))
其他:
通过

这是一条相对路径:

static/img/admin/...
请注意,开头没有任何
/

此路径等于以下路径:

http://example.com/current/page/url/static/img/admin/...

解决方案:

因此,您需要使用绝对路径(以
/
开头):

这将得到适当解决,以:

http://example.com/static/img/admin/...


有关的详细信息。

这是一个相对路径:

static/img/admin/...
请注意,开头没有任何
/

此路径等于以下路径:

http://example.com/current/page/url/static/img/admin/...

解决方案:

因此,您需要使用绝对路径(以
/
开头):

这将得到适当解决,以:

http://example.com/static/img/admin/...


有关的详细信息。

ty。这不会给生产带来任何麻烦吗?考虑到此文件将位于staticfiles而非static中,何时运行collect staticfiles?@OmarGonzales只要将
static\u URL
映射到适当的目录,它就会正常工作。ty。这不会给生产带来任何麻烦吗?考虑到此文件将位于staticfiles而非static中,何时运行collect staticfiles?@OmarGonzales只要将
static\u URL
映射到适当的目录,它就会正常工作。