django 将数组交给前台

for 

{% for %} 标签用于迭代序列中的各个元素,与Python的ofr 语句一样,语法是for X in Y,其中Y是要迭代的序列,

X是单词循环中使用的变量。

每次迭代时,模板系统会渲染{% for %}和{% endfor %}之间的内容。

def notice(req):
   #return render_to_response('polls/notice.html')
   #    return render(request, 'cmdb/year_archive.html', {
   #     'foo': aaaa,
   # })
   arr=['a1','b2','c3','d4']
   return render(req,'polls/notice.html',{'athlete_list':arr})


node2:/tlcb/mysite/polls/templates/polls#cat notice.html
<ul>
{% for athlete in athlete_list %}
<li>{{ athlete }}</li>
{% endfor %}
</ul>

http://192.168.137.3:9000/notice/

  
    a1
    b2
    c3
    d4

原文地址:https://www.cnblogs.com/hzcya1995/p/13349272.html