【问题标题】:Adding images to different poll question in django app - how to do?在 django 应用程序中将图像添加到不同的投票问题 - 怎么办?
【发布时间】:2018-04-16 07:49:57
【问题描述】:

我在 PythonAnywhere 上启动并运行了一个 django 应用程序,我想为不同的投票问题添加不同的图片。怎么做?

目前,我通过在 polls/detail.html 中插入图像链接来完成每个投票问题的相同图片

如何添加代码每次都有不同的图片?

即。 page: polls/1 - 将显示图片 1、polls/2 图片 2 等等。

【问题讨论】:

    标签: django image add


    【解决方案1】:

    将图像添加到您的问题模型

    class Question(models.Model):
        ...
        image:models.ImageField('upload_to'='images/')
        ...
    

    并显示该图像。

    <img src="{{ question.image.url  }}">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      • 2012-10-29
      • 2014-09-18
      • 2022-12-17
      相关资源
      最近更新 更多