django(模板语言)

模板语言是写在html中的

cur_time.html

<
body> <h1>当前时间:{{ currenttime }}</h1> //{{}}中是变量 </body> </html>


views.py

def cur_time(req):
curtime=datetime.datetime.now()
return render(req,"cur_time.html",{"currenttime":curtime}) #将前端中的currenttime变量替换成后端中的curtime
# return HttpResponse("<h1>nihoa</h1>")
 
<table border="1">
    {% for i in info_list %}                    //{%%}中是语句
        <tr>
            <td>{{ i.username }}</td>
            <td>{{ i.pwd }}</td>
        </tr>
    {% endfor %}
</table>


views.py
def userInfo(r):
return render(r, "userInfo.html",{"info_list":info_list}) #将前端中的info_list替换成后端中的info_list
 

猜你喜欢

转载自www.cnblogs.com/gaoyukun/p/8992492.html