Py学习  »  Django

为什么我的django循环在svg viewbox中显示相同的图像?

Bryan • 4 年前 • 294 次点击  

我正在使用django框架并尝试以多边形显示模型中的图像。为此,我使用svg。目前,它只是多次显示SMAE图像,而不是在数据库中显示所有图像。这是我的代码:

{% if images %}


<section id="gallery">
     <ul id="hexGrid">
  {% for image in images %}
  <li class="hex">

  <svg viewbox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <pattern id="img" patternUnits="userSpaceOnUse" width="100" height="100">
    <image xlink:href="{{image.src.url}}" x="-25" width="150" height="100" />
    </pattern>
  </defs>
  <polygon id="hex" points="50 1 95 25 95 75 50 99 5 75 5 25" fill="url(#img)"/>
  </svg>
  </li>
  {% endfor %}
</ul>
  </section>

{% else %}

<p>
  No Posts
</p>
{% endif %}

这是我的模型:

from django.db import models


class Images(models.Model):
    title = models.CharField(max_length=200)
    src = models.FileField(upload_to='images/', null=True, verbose_name="")

我做错什么了?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46334
 
294 次点击