本文實例講述了Django框架模板注入操作。分享給大家供大家參考,具體如下:
1.HTML模板如何解析變量?
<h1>這是一個html頁面</h1><p>id:{{ user_id }}</p><p>名字:{{ username }}</p> 其中:{{變量名}}
2.如何傳遞數據到HTML模板上?
#coding:utf-8from django.shortcuts import render,render_to_response# Create your views here.from django.http import HttpResponsedef hi(request): user = {'user_id':1,'username':'張三','username':'李四'} return render_to_response("index.html",user)user是定義的字典,鍵可以重復,同名鍵值打印最后添加的
3.最后模板效果
希望本文所述對大家基于Django框架的Python程序設計有所幫助。
新聞熱點
疑難解答