谁知道问题是什么以及如何解决它,我将尝试解释。我有两个项目,两个数据库:一个仓库和一个商店,当新产品到达仓库时,商店执行任务并检查需要将多少产品添加到商店的数据库中,或者如果是新产品,则添加它。图片有问题
模型仓库:
class Book(models.Model):
author = models.ForeignKey('Author', on_delete=models.CASCADE)
genre = models.ForeignKey(Genre,
related_name='books',
on_delete=models.CASCADE)
title = models.CharField(max_length=255)
description = models.TextField(blank=True)
language = models.CharField("language", max_length=20)
pages = models.IntegerField()
image = models.ImageField(upload_to='products/%Y/%m/%d')
slug = models.SlugField(max_length=255)
price = models.DecimalField(max_digits=10, decimal_places=2)
isbn = models.CharField('ISBN', max_length=13,
unique=True)
created = models.DateTimeField(auto_now_add=True)
available = models.BooleanField(default=True)
quantity = models.IntegerField()
这里一切正常,它将图片保存在media/products
模型存储:
class Book(models.Model):
author = models.ForeignKey('Author', on_delete=models.CASCADE)
genre = models.ForeignKey(Genre,
related_name='books',
on_delete=models.CASCADE)
title = models.CharField(max_length=255)
description = models.TextField(blank=True)
language = models.CharField("language", max_length=20)
pages = models.IntegerField()
image = models.URLField(validators=[URLValidator()])
slug = models.SlugField(max_length=255)
price = models.DecimalField(max_digits=10, decimal_places=2)
isbn = models.CharField('ISBN', max_length=13,
unique=True)
created = models.DateTimeField(auto_now_add=True)
available = models.BooleanField(default=True)
quantity = models.IntegerField()
商店图像中字段的正确名称是什么?
链接到任务芹菜:https://dpaste.com/G6HJBSJAY
screen from API and Image url
后芹菜任务我如何进入商店
这是您的商店项目中的image
字段。下面是你在HTML上渲染它的方法:-
<img src="{{book.image}}" alt="Book image" width="500" height="600">
让我们考虑您的数据库将下面的数据存储到存储项目的image字段中。
完整URL:-
https://1.bp.blogspot.com/-63yzpaIPb8o/YSz6iG-BoRI/AAAAAAAAMr4/6iQ-opW8qgoKi4Pc69iMakii4NdVUTQ6ACLcBGAsYHQ/s2048/Jain-Panchang-Calendar-2021-September.jpg
图像标签将是:-
<img src="https://1.bp.blogspot.com/-63yzpaIPb8o/YSz6iG-BoRI/AAAAAAAAMr4/6iQ-opW8qgoKi4Pc69iMakii4NdVUTQ6ACLcBGAsYHQ/s2048/Jain-Panchang-Calendar-2021-September.jpg" alt="Book image" width="500" height="600">