当前位置:编程学习 > 网站相关 >>

Django项目5

准备工作
[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>  
 
补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,