1、index <html> <head> <title>DOcument</title> </head> <body> <h1>{{user}}</h1> </br> </br> <h1>reversed关键字</h1> {% for book in user reversed %} <li>{{book}}</li> {% endfor %} </body> </html>
2、views.py # -*- coding: cp936 -*- from django.http import HttpResponse from django.template import loader,Contextdef index(request): t=loader.get_template(‘index.html‘) bookList=[‘python‘,‘C++‘,‘java‘,‘php‘] #向html页面传递数据 c=Context({‘user‘:bookList}) #渲染方法 t=t.render(c) return HttpResponse(t)
时间: 2024-11-01 03:27:21