我有以下success function
ajax调用,它为图像创建HTML并将其附加到div
。用Django模板标签内部的JavaScript变量代替
success:function(response)
{
var new_comment = $('<div class="row" style="background-color:white;margin:5px;">{% thumbnail '+response.author_image+' "35x35" crop="center" as im %}<img src = "{{im.url}}" width="{{im.width}}" height="{{im.height}}" >{% endthumbnail %}')
$(".comments").append(new_comment);
},
我使用sorl-thumbnail应用程序来显示模板中的图像。这是通过{% thumbnail url ...%}
标签完成的,该标签需要图像的url。
此URL存储在response.author_image
和Im试图在模板标记内替换此值。
response.author_image
通过
{% thumbnail '+reponse.author_image'+ ... %}
保持此值'/media/Images/Profile_2_(PSF)_5.png'
这样做是替代变量名称,而不是它的值:
[Errno 2] No such file or directory: u'/home/hammad/virt_env/virt1/gccFishing/gccFishing/media/+response.author_image+'
我怎么能代替的response.author_image
值内thumbnail template tag
?
TIA