django加載本地html的方法
django加載本地html
from django.shortcuts import render from django.http import HttpResponse from django.shortcuts import render,render_to_response # Create your views here. def hello(request): return render_to_response("hello.html")
傳遞數(shù)據(jù)到html中
python代碼
# Create your views here. # http://weibo.com/lixiaodaoaaa class Person(object): def __init__(self, name, age, sex): self.name = name self.age = age self.sex = sex def say(self): return self.name def hello(request): u_user = Person("dog", 18, "male") myList = ["sendList to the html files", "god", "god02"] u_content_dic = {"u_title": "Title Is Here", "u_user": u_user,"u_test_str":myList} ##傳遞一個(gè)字典作為Content_type return render_to_response("hello.html", u_content_dic)
Html代碼去取值:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>{{ u_title }}</title> <h1>{{ u_user.age }}</h1> <h1>{{ u_user.name }}</h1> <h1>{{ u_user.sex}}</h1> <h1>{{ u_test_str.0}}</h1> <h1>{{ u_test_str.1}}</h1> <br/> <h1>{{ u_user.say}}</h1> </head> <body> </body> </html>
以上這篇django加載本地html的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python itchat實(shí)現(xiàn)調(diào)用微信接口的第三方模塊方法
這篇文章主要介紹了python itchat實(shí)現(xiàn)調(diào)用微信接口的第三方模塊方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06Python實(shí)現(xiàn)json對(duì)值進(jìn)行模糊搜索的示例詳解
我經(jīng)常使用json進(jìn)行存儲(chǔ)配置,于是常常遇到這樣的問(wèn)題:如果想要對(duì)某個(gè)數(shù)組里的值進(jìn)行模糊搜索,同時(shí)輸出相關(guān)的其他數(shù)組相同位置的的值該如何實(shí)現(xiàn)呢?本文就來(lái)和大家詳細(xì)聊聊2023-01-01詳解Python的Django框架中manage命令的使用與擴(kuò)展
這篇文章主要介紹了Python的Django框架中manage命令的使用與擴(kuò)展,manage.py使得用戶借助manage命令在命令行中能實(shí)現(xiàn)諸多簡(jiǎn)便的操作,需要的朋友可以參考下2016-04-04PyCharm活動(dòng)模板設(shè)置步驟實(shí)現(xiàn)
很多情況,我們?cè)趯懘a都會(huì)存在經(jīng)常要寫一些簡(jiǎn)單且又重復(fù)的代碼,Pycharm中的活動(dòng)模板可以把這些使用頻率很高的一些代碼打包起來(lái)設(shè)置一個(gè)快捷鍵,本文就來(lái)介紹一下如何實(shí)現(xiàn)2023-12-12django 鏈接多個(gè)數(shù)據(jù)庫(kù) 并使用原生sql實(shí)現(xiàn)
這篇文章主要介紹了django 鏈接多個(gè)數(shù)據(jù)庫(kù) 并使用原生sql實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Python實(shí)現(xiàn)Tab自動(dòng)補(bǔ)全和歷史命令管理的方法
這篇文章主要介紹了Python實(shí)現(xiàn)Tab自動(dòng)補(bǔ)全和歷史命令管理的方法,實(shí)例分析了tab自動(dòng)補(bǔ)全的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03