I'm trying to get Sorl-thumbnail running on my staging server, but I'm running into a TemplateSyntaxError which is throwing me since the app works fine on localhost.
The error is coming in at {% endthumbnail %}
TemplateSyntaxError at /home/
Invalid block tag: 'endthumbnail', expected 'endif'
Any help would be greatly appreciated. Thanks!
{% load thumbnail %}
{% if picture.photo_medium %}
<img src="{{AWS_URL}}{{picture.photo_medium}}" class="imagepage" width="400" height="300">
{% else %}
{% if picture.photo_large|is_portrait %}
<div class="portrait">
{% thumbnail picture.photo_large "400" crop="center" as im %}
<img src="{{AWS_URL}}{{ im }}">
</div>
{% else %}
<div class="landscape">
{% thumbnail picture.photo_large "400" crop="center" as im %}
<img src="{{AWS_URL}}{{ im }}">
</div>
{% endif %}
{% endif %}
It is likely that you have an older version of sorl-thumbnail installed on your localhost than is installed on your staging server. The endthumbnail tag was added relatively recently as part of a major rewrite.
If you find that you need to upgrade you may find the setting THUMBNAIL-DEBUG helpful for tracking down other problems.
I might be wrong, but I don't think you need the {% endthumbnail %} tag.
The problem can also be with loading template tags.
I was doing {% load thumbnail %} in base html.
When I call below code in inherited html, got same error.
{% thumbnail service_type.pic.image "100x100" crop="center" as im %}
<img .....>
{% endthumbnail %}
See this discussion about loading template tags in base.html
I just ran into this problem in using SORL Thumbnail in Mezzanine. Apparently Mezzanine loads it's own thumbnailer, so if you {% load thumbnail mezzanine_tags %}, mezzanine's thumbnail takes over from SORL's Thumbnail tag. However, if you reverse it {% load mezzanine_tags thumbnail %}, it works fine.
Lesson Learned: Make sure other libraries you're using aren't inadvertently taking over, and just to be safe maybe load thumbnail last.
Related
I'm trying to use the bootswatch flatly theme. I followed the instructions given on the documentation regarding updating the settings.
I've added the following to my project's settings.py:
BOOTSTRAP3 = { 'theme_url': 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css', }
I've also added the following to my project's base.html template, between the head tags:
{% load bootstrap3 %}
{% bootstrap_css %}
{% bootstrap_javascript %}
{% bootstrap_messages %}
index.html template:
{% extends "base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% bootstrap_css %}
{% block content %}
Hello World
{% endblock %}
However, the theme is not reflected when I reload my index page.
Is there something I'm doing wrong?
Edit: a temporary workaround I've found is to overwrite the css loaded by django-bootstrap3 by adding <link rel="stylesheet" href='https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css'> to the base.html template file, but I'd much prefer a solution using only django-bootstrap3.
Found out that this is a known issue, and has been fixed recently in the develop branch of the django-bootstrap repository. However, the pip package hasn't been updated yet.
Temporarily fixed this by editing my venv copy of django-bootstrap3.
I am using Django 1.10 and have this library installed 'nested_inline. I really need this lib however when I load the admin page it gives me the following error.
TemplateSyntaxError at /masterproducts/product/add/
'future' is not a registered tag library. Must be one of:
admin_list
admin_modify....
Also the stacktrace is as follows
{% load i18n admin_static admin_modify %}
{% load cycle from future %}
<div class="inline-group{% if recursive_formset %}
{{ recursive_formset.formset.prefix|default:"Root" }}
-nested-inline{% if prev_prefix %} {{ prev_prefix }}
-{{ loopCounter }}-nested-inline{% endif %}
nested-inline{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-group">
{% with recursive_formset=inline_admin_formset stacked_template='admin/edit_inline/stacked-nested.html' tabular_template='admin/edit_inline/tabular-nested.html'%}
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}" id="{{ recursive_formset.formset.prefix }}">
{{ recursive_formset.formset.management_form }}
<fieldset class="module">
<h2>{{ recursive_formset.opts.verbose_name_plural|capfirst }}</h2>
{{ recursive_formset.formset.non_form_errors }}
<table>
<thead><tr>
{% for field in recursive_formset.fields %}
I think cycle is now a django build-in templatetag, so there's no need to include it using {% load cycle from future %}.
docs
Ok fine got it. I just followed the answer on this thread https://github.com/iambrandontaylor/django-admin-sortable/issues/151 Below is the solution
# templatetags/future.py
from django.template import Library
from django.template.defaulttags import cycle as cycle_original
register = Library()
#register.tag
def cycle(*args, **kwargs):
''' A stub to get SortableTabularInline to work '''
return cycle_original(*args, **kwargs)
I couldn't understand what exactly to do with this as I rarely use templates. Apparently your supposed to create a directory called templatetags in your app folder and then add the future.py file to it with the code above. For more help on where to place the templatetags folder refer this https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#code-layout
The issue was fixed in the latest commit: https://github.com/s-block/django-nested-inline/issues/65. It should work fine if you directly install the package from Github.
Suppose, I have 20 images of size 1600 X 900 in a page. How do I load the images in the size that I specify on a template? In the css I can do it. But I want to change the actual size of the image, so that when clicked on the particular image, it will load the original image with its original size. Is there any way that I can do it? I tried using easy_thumbnails and it was great, until it gave me problems when I deployed it using the apache server. Any help will be deeply appreciated. Thank you!
EDIT:
.html:
{% for Status in status %}
<p class="user">{{ Status.creator.get_full_name }}</p>
{% if Status.image %}
<div class="image_image">
<center>
<img src="{{ MEDIA_URL }}{{Status.image}}" width=300px />
</center>
</div>
<p class="status_image">{{Status}}</p>
<span class="clear"></span>
<hr>
{% else %}
<p class="status_status">{{Status}}</p>
<span class="clear_right"></span>
<hr>
{% endif %}
{% endfor %}
Try to use sorl thumbnail, it even supports Amazon S3 Server.
pip install sorl-thumbnail
To Installed apps:
'sorl.thumbnail',
add {% load thumbnail %} to your template.
{% thumbnail firma.firma_logo "130x110" format="PNG" as im %}
<div class="logo" style="background-image:url('{{ im.url }}')"></div>
{% endthumbnail %}
The make image format PNG is important, it converts into JPEG by the default. And if the user uploads file in transparent format, it sucks.
I am using django-gravatar and I am wondering how to display a local image to use as a default image. Is there a way to do so?
I have read in the docs to use GRAVATAR_DEFAULT_IMAGE, but it does not seem to work specifying the path to the image within the static/ directory. Is it only for online images from other websites?
Thanks!
EDIT
I am using the following configuration:
STATIC_URL = '/static/'
GRAVATAR_DEFAULT_IMAGE = STATIC_URL + 'img/StartMyProjects_100.png'
Hack finally used to solve the problem:
<img class="media-object" src="
{% if profile.gravatar_email %}
{% gravatar_for_email profile.gravatar_email %}
{% else %}
/static/img/StartMyProjects_100.png
{% endif %}"
alt="{{ profile.full_name }}">
To solve the problem, as stated in the edited question, I actually used an if-else (in Django). Maybe someone knows a better way to do so, but this worked for me!
<img class="media-object" src="
{% if profile.gravatar_email %}
{% gravatar_for_email profile.gravatar_email %}
{% else %}
/static/img/StartMyProjects_100.png
{% endif %}"
alt="{{ profile.full_name }}">
I've noticed that Django 1.3 introduced the new "localize" tag/filter.
http://docs.djangoproject.com/en/1.3/topics/i18n/localization/
It says:
To activate or deactivate localization
for a template block, use:
{% localize on %}
{{ value }}
{% endlocalize %}
{% localize off %}
{{ value }}
{% endlocalize %}
However I always got the error message:
Invalid block tag: 'localize'
Looks like the "localize" filter doesn't work as well. Can anybody help me? Or can anybody else confirm if this is a bug? Thanks!
Have you loaded the localization template tags with:
{% load l10n %}
before using "localize" template tag?