I want to resize my static files with sorl thumbnail but it doesnt work
here is my codes
{% if not new.photo %}
{% with path="{{STATIC_URL}}/images/empty-news.jpg" %}
{% thumbnail path "80x80" crop="center" as im %}
<a href="#" class="image"><img alt="" src="{{im.url}}" class="frame2"></a>
{% endthumbnail %}
{% endwith %}
{% else %}
{% thumbnail new.photo "80x80" crop="center" as im %}
<a href="{% url news_detail new.slug %}" class="image">
<img alt="" src="{{im.url}}" class="frame2"></a>
{% endthumbnail %}
{% endif %}
If I have image it shows image but when I dont have image I cant use default image because thumbnail doesn't work
Ugly option that worked for me, passing in the path that you would normally pass to the static
template tag (note that it assumes the http protocol, so it could be improved):
{% with 'http://'|add:request.get_host|add:STATIC_URL|add:image_path as path %}
{% thumbnail path "720x306" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
{% endwith %}
This works by building up the absolute path to the static image.
Honestly...this looks fine; which means there is probably something simple wrong in your setup.
Possible bad setup:
How are you defining STATIC_URL in your settings? Also, what is the value of DEBUG (make sure this is set to True
if you're developing locally)? As @goliney pointed out, your path might be messed up. Try pulling out the thumbnail blocks out, and set the src of your image to {{ STATIC_URL }}/images/empty-news.jpg
and verify that works before trying to do the thumbnails.
Forgot to load thumbnails: Make sure to put {% load thumbnail %}
in your template before any references to the {% thumbnail %}
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With