经验分享 – 100 – 在Django模板中使用循环

如何在Django模板中使用循环指令,请举例说明

# myfor.py
from django.shortcuts import render
class MyClass:
    name = 'Bill'
def myFor(request):
    values = {'values': [{'name':'item1'}, MyClass(), {'name':'Mike'}]}
    return render(request, 'for.html', values)

# urls.py
from django.conf.urls import url
from . import myfor

urlpatterns = [
    url(r'^for$', myfor.myFor)
]

正文完