時間:2023-06-11 12:24:01 | 來源:網(wǎng)站運營
時間:2023-06-11 12:24:01 來源:網(wǎng)站運營
Python Web開發(fā)06-django模板:'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>
#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))
#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 庫讓你相見恨晚?
關鍵詞:模板
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。