首页 > 安全资讯 >

Django项目5

13-01-07

准备工作[plain] django-admin.py startproject web05 django-admin.py startapp blog blog注册到settings.py中 python manage.py runserver 配置url[python]from django.conf.urls.defaults impor...

准备工作
[plain]  
django-admin.py startproject web05  
django-admin.py startapp blog  
blog注册到settings.py中  
python manage.py runserver  
配置url
[python] 
from django.conf.urls.defaults import patterns, include, url   
urlpatterns = patterns('',  
    url(r'^blog/index/$','blog.views.index'),  
)  
配置views
[python]  
#coding:utf8  
from django.http import HttpResponse  
from django.template import loader,Context  
import datetime  
  
def index(req):             #req只是用来request而已,用别名也可  
    t=loader.get_template('index.html')  
    now = datetime.datetime.now()  
    emps = [   
        {},   
        {},   
        {},   
    ]     
    c=Context({  
        'a':123,  
        'now':now,  
    })    
    html = t.render(c)  
    return HttpResponse(html)  
配置html,过滤器!
[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>  
{{a|add:'2'}}<br />  
{{now|date:'Y m d H i s'}}  
</body>  
</html>  
 
相关文章
最新文章
热点推荐