我有以下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