国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運營 > Python Web開發(fā)06-django模板

Python Web開發(fā)06-django模板

時間:2023-06-11 12:24:01 | 來源:網(wǎng)站運營

時間:2023-06-11 12:24:01 來源:網(wǎng)站運營

Python Web開發(fā)06-django模板:

四喜接著來!

模板

創(chuàng)建模板




'DIRS': [os.path.join(BASE_DIR, 'templates')],


定義模板

{{變量名}}{%代碼段%}<html><head> <title>圖書列表</title></head><body><h1>{{title}}</h1>{%for i in list%}{{i}}<br>{%endfor%}</body></html>

視圖調(diào)用模板




#coding:utf-8from django.http import HttpResponsefrom django.template import loader,RequestContextdef index(request): # 1.獲取模板 template=loader.get_template('booktest/index.html') # 2.定義上下文 context=RequestContext(request,{'title':'圖書列表','list':range(10)}) # 3.渲染模板 return HttpResponse(template.render(context))


視圖調(diào)用模板簡寫




#coding:utf-8from django.shortcuts import renderdef index(request): context={'title':'圖書列表','list':range(10)} return render(request,'booktest/index.html',context)
友情提供
1.新手學習Python推薦的學習資源
2.Python 應該怎么學?
3.哪些 Python 庫讓你相見恨晚?

整理Python Web開發(fā)資料匯總
01-四喜Clion:Python Web開發(fā)-django搭建環(huán)境
02-四喜Clion:Python Web開發(fā)02-django創(chuàng)建圖書管理項目
03-四喜Clion:Python Web開發(fā)03-django模型設計
04-四喜Clion:Python Web開發(fā)04-django后臺管理
05-四喜Clion:Python Web開發(fā)05-django視圖

下期整理 django 項目+源碼 點擊 @四喜Clion一起python到底~

關鍵詞:模板

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關閉