I just created a custom template tag.
from django import template
from lea.models import Picture, SizeCache
register = template.Library()
@register.simple_tag
def rpic(picture, width, height, crop=False):
return SizeCache.objects.get_or_create(width=width, height=height, picture=picture, crop=crop)[0].image_field.url
This works except for the optional parameter crop. The optional parameter can be set, but is ignored by the function and always set to False.
simple_tagworks as Python invoking similarly.If your are passing literal
Truein template, it would be treated as a variable namedTrueand be searched in template context. If there is notTruedefined, the value becomes''and coerced toFalseby Django, as long as thecropfield is amodels.BooleanField.For example,
in foo/templatetags/foo.py
in shell