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")

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}
## 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 를 불 러 오 는 방법 은 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 여러분 들 이 저 희 를 많이 사랑 해 주 셨 으 면 좋 겠 습 니 다.