Django(14) For Loop in Django Template

In last tutorial, we create a list in python file and display it on our webpage. But it doesn't make sense. If you want to get each programming language in it, here are some tips.

For Loop in Django Template

  1. Open "news.html", and add these codes below {{ list }}. You will find the syntax is similar to what we used in python.
{% for language in list %}

<ul>
    <li>{{language}}</li>
</ul>

{% endfor %}
  1. Refresh launched page, you will see update.


    Django(14)_For_Loop_in_Django_Template_1.png

So far, you have learnt how to use for loop in html file to interact data with python file in Django. Hopefully, it helps.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 模板标签除了几个常用的,还真心没有仔细了解一下,看到2.0发布后,翻译学习一下。 本文尽量忠实原著,毕竟大神的东西...
    海明_fd17阅读 2,045评论 0 5
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,726评论 0 3
  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,227评论 0 3
  • 我在这里呆了很久, 很高兴吃过饭、喝过酒、迷过路。 很高兴穿在身上的小毛衣起了毛球, 剪下去,蹭一蹭又长起来。 我...
    爱伦同学阅读 359评论 0 2
  • 敬爱的王院长,智慧的高管们,勤奋的家人们,大家晚上好,我是视光中心执行部王珏,今天是2018年11月9日,是我日精...
    王珏_100e阅读 265评论 0 1