我的模板无法显示来自我的模型的图片。
虽然 src 属性与相应字段匹配,但它并未显示正确的图片。
模板:
<div class="grid-product">
{% for p in prod %}
<div class=" product-grid">
<div class="content_box"><a href="single.html">
<div class="left-grid-view grid-view-left">
<img class="img-responsive watch-right" alt="not found" src="{{p.photo}}"/>
<div class="mask">
<div class="info">Quick View</div>
</div>
</a>
</div>
<h4><a href="#"></a></h4>
<p>It is a long established fact that a reader{{ p.p_name }}</p>
Rs. 499
</div>
</div>
{% endfor %}
<div id="show"></div>
<div class="clearfix"> </div>
</div>
模型:
class product(models.Model):
p_id=models.AutoField(primary_key=True)
ps_id=models.ForeignKey(alphasubcat,on_delete=models.CASCADE)
p_name=models.CharField(max_length=100,null=True,blank=True)
photo = models.ImageField(upload_to='productimage',blank=True)
price=models.IntegerField()
def __str__(self):
return self.p_name
视图:
def produc(request):
param=dict()
cat=categories.objects.all()
sub=subcategories.objects.all()
temp=request.GET['p']
prod=product.objects.filter(ps_id=alphasubcat.objects.get(as_name=temp))
param['prod']=prod
param['cat']=cat
param['sub']=sub
return render(request,"product.html",param)