1.modify settings.py to add templates folder on project
#mkdir templates
#vim settings.py
import os.path
TEMPLATE_DIRS = (
os.path.join( os.path.dirname( __file__ ), 'templates' ),
)
2.add new main_page.html on templates
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{ head_title }}</title>
</head>
<body>
<h1>{{ page_title }}</h1>
<p>{{ page_body }}</p>
</body>
</html>
3.modify views.py
from django.http import HttpResponse
from django.template import Context
from django.template.loader import get_template
def main_page( request ):
template = get_template( 'main_page.html' )
variables = Context( {
'head_title':'Django Bookmarks',
'page_title':'Welcome to use Django frameworkd',
'page_body':'Where you can store and share bookmarks',
} )
output = template.render( variables )
return HttpResponse( output )
2011年5月4日 星期三
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言