Django 学习笔记一
2013-08-12 18:52
375 查看
1、Django请求流程:
(1) 进来的请求转入/hello/(2)Django通过在ROOT_URLCONF配置来决定根URLconf
(3)Django在URLconf中的所有URL模式中,查找第一个匹配/hello/的条目
(4)如果找到匹配,将调用相应的视图函数
(5)视图函数返回一个HttpResponse
(6)Django转换HttpResponse为一个适合的HTTP response,为Web page显示
2、from django.conf import settings
settings.configure
#coding=utf-8 ''' Created on 2013-8-12 @author: net ''' from django.template import Template, Context from django.conf import settings settings.configure() class Person(object): def __init__(self, firstname, lastname): self.firstname = firstname self.lastname = lastname if __name__ == "__main__": t = Template("我姓:{{person.firstname}} 名: {{person.lastname}}") c = Context({"person": Person("陈", "真")}) print t.render(c)运行结果:
pydev debugger: starting 我姓:陈 名: 真
3、django 标签
(1) {% if %}(2) {% for %}
(3) {% ifequal %}
(4) {% ifnotequal %}
(5) {# fdfdf #}
(6) {% comment %} {% endcomment %}
(7)过滤器 {{name | filter}}
{{time | date: "F, j, Y"}}
4、
from django.shortcuts import render_to_response import datetime def current_datetime(request): now = datetime.datetime.now() return render_to_response('current_datetime.html', {'current_date': now})
5、Django.contrib
管理工具是本书讲述django.contrib的第一个部分。从技术层面上讲,它被称作django.contrib.admin。django.contrib中其它可用的特性,如用户鉴别系统(django.contrib.auth)、支持匿名会话(django.contrib.sessioins)以及用户评注系统(django.contrib.comments)。这些,我们将在第十六章详细讨论。在成为一个Django专家以前,你将会知道更多django.contrib的特性。目前,你只需要知道Django自带很多优秀的附加组件,它们都存在于django.contrib包里。
相关文章推荐
- 菜鸡的Django学习笔记(二)如何创建第一个博客页面
- Python学习笔记22:Django下载安装
- Pyhton_Django学习笔记(一) Django安装 导入项目 运行服务器
- Django框架学习笔记(28.文件上传详解)
- Django学习笔记 Day One
- Django学习笔记之简介
- Django学习笔记
- 【django 学习笔记】05-admin
- django学习笔记1:安装
- 【django 学习笔记】18-国际化
- Django学习笔记-简单的Demo
- Django学习笔记(精简版)
- Django学习笔记(一)安装
- Django学习笔记2
- Django 学习笔记(十三)
- Django的select_related查询学习笔记
- python学习笔记--Django入门四 管理站点
- Django框架学习笔记(8.对应路由名称和路由分发)
- Django 学习笔记(二)