html页面已经写好,需要用python查找相关文件夹,把文件夹的图片遍历一遍,然后返回绝对路径到html中,现在用python已经把返回图片路径功能完成,在django中每个文件要怎么写,另外我的html不在django创建的文件夹中
把html做成模板啊。把文件路径列表传到模板里,由模板引擎解析它追问
def get_path(resquest):
#do some thing
path_list = function(#)
return render_to_response('temp.html',{'path_list':path_list})
{% for path in path_list %}
<img src={{ path }}>
{% endfor %}
用{% for %}{% endfor %}可以吗?function的作用是遍历文件夹下所有图片的绝对路径,#是文件夹的路径
追答把{{ function(#) }}放到视图中,将其返回的文件列表作为path_list传进模板
视图函数def get_path(resquest):
#do some thing
path_list = function(#)
return render_to_response('temp.html',{'path_list':path_list})
{% for path in path_list %}
<img src={{ path }}>
{% endfor %}
温馨提示:答案为网友推荐,仅供参考