我的Django网站上的图片未加载

时间:2019-07-11 05:43:01

标签: html css django django-templates

我的菜单模板上有图像,单击该图像时我想重定向到Django中的另一个模板

**Below is my code for the menu template:**

 {%for count in item%}
        <div class="col-md-6 col-lg-4 menu-wrap">
            <div class="heading-menu text-center ftco-animate">
                <h3>{{count.supper}}</h3>
                </div>
            <div class="menus d-flex ftco-animate">
          <div class="menu-img img" style="background-image: url({{count.pic.url}});"></div>
          <div class="text">
            <div class="d-flex">
                <div class="one-half">
                  <h3>{{count.name}}</h3>
                </div>
                <div class="one-forth">
                  <span class="price">${{count.price}}</span>
                </div>

我如何做到这一点? 可以应用onclick事件吗?

Model.py代码:

从django.db导入模型 从django.contrib.postgres.fields导入ArrayField

class Breakfast(models.Model):

    name = models.CharField(max_length=100)
    price = models.IntegerField()
    ingredients = ArrayField(models.CharField(max_length=100),size=8)
    pic = models.ImageField(upload_to="images")


class Lunch(models.Model):

    name = models.CharField(max_length=100)
    price = models.IntegerField()
    ingredients = ArrayField(models.CharField(max_length=100),size=8)
    pic = models.ImageField(upload_to="images")

1 个答案:

答案 0 :(得分:0)

直接放置图片而不是背景

<div class="menu-img img">
  <a href="{% url 'whatdoyouwant' %}">
    <img src="{{count.pic.url}}"></img>
  </a>
</div>