Django项目6
准备工作
[plain]
django-admin.py startproject web05
django-admin.py startapp blog
blog注册到settings.py中
python manage.py runserver
blog下建立templates,并建立两个模板文件
配置url
[python]
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^blog/index/$','blog.views.index'),
url(r'^blog/show/$','blog.views.show'),
)
配置views
[python]
#coding:utf8
from django.http import HttpResponse
from django.template import Template,Context,loader
from django.shortcuts import render_to_response #先导入这个牛逼的东西
def index(req):
t = Template('<h1>name is:{{uname}}</h1>')
c = Context()
c['uname']='tom'
res = HttpResponse(t.render(c))
res.write('aaa') #response可追加,用write方法
return res
def show(req):
return render_to_response('show.html',{'name':'dragon'})#一行搞定别人五行
配置html
[html]
<!-- base.html是模板文件 这里面就一个测试语句 -->
<h1>test</h1>
[html]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body>
<b>welcom {{name}}</b>
<div>
{%include 'base.html'%}
</div>
</body>
</html>
补充:Web开发 , Python ,