简体   繁体   English

Django - 在模板标签内标记

[英]Django - Tag inside a Template tag

So I'm using the django-jcrop plugin to crop an image. 所以我使用django-jcrop插件来裁剪图像。 Inside my HTML file I have this line: 在我的HTML文件中,我有这一行:

<img src="{% cropped_thumbnail order 'cropping' max_size='{{ ratio }}' %}">

When this is passed, I get the following error: 通过后,我收到以下错误:

TemplateSyntaxError: max_size must match INTxINT

{{ ratio }} is passed correctly outside of the tag, and gives the correct intended value, 400x400. {{ ratio }}在标记之外正确传递,并提供正确的预期值400x400。 When I remove the single quotes from the max_size='{{ ratio }}' I then get the following error: 当我从max_size='{{ ratio }}'删除单引号时,我会收到以下错误:

TemplateSyntaxError: Could not parse the remainder: '{{' from '{{'

So I am pretty sure ratio is not parsing correctly within the tag. 所以我很确定比率在标签内没有正确解析。 Any ideas why? 有什么想法吗?

在模板标记内,您不需要使用“{{}}”,您可以尝试下一个代码:

<img src="{% cropped_thumbnail order 'cropping' max_size=ratio %}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM