【发布时间】:2018-04-16 07:49:57
【问题描述】:
我在 PythonAnywhere 上启动并运行了一个 django 应用程序,我想为不同的投票问题添加不同的图片。怎么做?
目前,我通过在 polls/detail.html 中插入图像链接来完成每个投票问题的相同图片
如何添加代码每次都有不同的图片?
即。 page: polls/1 - 将显示图片 1、polls/2 图片 2 等等。
【问题讨论】:
我在 PythonAnywhere 上启动并运行了一个 django 应用程序,我想为不同的投票问题添加不同的图片。怎么做?
目前,我通过在 polls/detail.html 中插入图像链接来完成每个投票问题的相同图片
如何添加代码每次都有不同的图片?
即。 page: polls/1 - 将显示图片 1、polls/2 图片 2 等等。
【问题讨论】:
将图像添加到您的问题模型
class Question(models.Model):
...
image:models.ImageField('upload_to'='images/')
...
并显示该图像。
<img src="{{ question.image.url }}">
【讨论】: