【问题标题】:django cms picture resizedjango cms 图片调整大小
【发布时间】:2015-03-02 04:31:39
【问题描述】:

我是 Django CMS 的新手。我可以在 Django 中通过 CSS 调整某些东西的大小,但是这个过程会减慢我的速度,所以我认为使用 Django CMS 会更快。好的,现在我使用 Django CMS 获得了欢迎页面,然后我从添加图片开始,并惊讶地发现没有调整大小的选项。我找到了类似 sorl_thumbnail 包的东西,但不知道如何将代码集成到我的模板中。以下是来自 sorl_thumbnail 的教程:

{% load thumbnail %}

{% thumbnail item.image "100x100" crop="center" as im %}
    <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %} 

在我的 feature.html 模板中:

{% extends "base.html" %}
{% load cms_tags staticfiles sekizai_tags menu_tags %}
{% block content %}
<div>
    {% placeholder "feature" %}
</div>
<div>
    {% placeholder "content" %}
</div>
{% endblock content %}

sorl_thumbnail 的教程没用,没有说他们的代码放在哪里。我试图粘贴整个东西,但没有运气。请各位大神帮忙!

【问题讨论】:

    标签: django-cms sorl-thumbnail


    【解决方案1】:

    djangocms-picture 插件比较基础,请查看 cmsplugin-filer (https://pypi.python.org/pypi/cmsplugin-filer/0.10) 插件了解更高级的图片插件

    【讨论】:

      【解决方案2】:

      我也会推荐@yakky 提到的cmsplugin_filer_image

      见:https://github.com/stefanfoulis/cmsplugin-filer/tree/develop/cmsplugin_filer_image

      但如果你想继续使用djangocms-picture,你需要覆盖插件模板。

      将下面的 sn-p 复制到您的 template 目录中的 cms/plugins/picture.html

      {% load thumbnail %}
      
      <span class="plugin_picture{% if picture.float %} align-{{ picture.float }}{% endif %}">
          {% if link %}<a href="{{ link }}">{% endif %}
              {% thumbnail picture.image "100x100" crop="center" as im %}
                  <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
              {% endthumbnail %} 
          {% if link %}</a>{% endif %}
      </span>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-22
        • 1970-01-01
        • 2023-04-01
        • 2017-06-18
        • 2013-02-22
        • 2016-08-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多