在ajax函数中使用Flask的url_for

时间:2017-06-10 15:27:48

标签: javascript python ajax flask

我正在使用Flask创建一个小的WebApp。在file.py中有一个

render_template('index.html', listaimmagini = listaimmagini) 

其中" listaimmagini"是图像名称列表(根据Flask标准,图像在静态文件夹中)。现在在" index.html"我试图展示这些图片,但似乎webapp并没有在静态文件夹中找到它(我的所有图片都有通常的破损图标)

我的代码中的错误在哪里?

的index.html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
window.onload = function(){

var img = [];
{% for imagelego in listaimmagini %}
img.push("{{url_for('static', filename = imagelego)}}");
{% endfor %}


    var parent = document.getElementsByClassName('scroll')[0];
    if(img.length>0){
        parent.style.overflowY = 'scroll';
        for(i=0;i<img.length;i++){
            image = document.createElement('IMG');
            image.src = img[i][0];
            image.alt = '';
            image.setAttribute("class", "scegli");
            parent.appendChild(image);
        }
</script>

0 个答案:

没有答案
相关问题