SlideShare une entreprise Scribd logo
1  sur  22
Django


                   Tao He
         elfinhe@gmail.com



                @SELAB, SYSU




                         1/20
Install
                     Install Python
                     Set up a database
                     Install Django
                           tar xzvf Django-NNN.tar.gz
                           sudo python setup.py install




http://docs.djangoproject.com/en/dev/intro/install         2/20
Writing your first Django app
   import django
   django-admin.py startproject mysite
       mysite/
          __init__.py

          manage.py 对 Django 进行脚本管理

          settings.py 项目配置

          urls.py URL 分配器配置

       python manage.py runserver 启动开发服务器
       wget -O- -q http://127.0.0.1:8000/ 测试服务器
       python manage.py runserver 192.168.128.141:80


                                                        3/20
Database setup
   vim settings.py
       'ENGINE': 'django.db.backends.sqlite3‘
       ‘NAME’:’mysite’
   python manage.py syncdb




                                                 4/20
Creating models
   python manage.py startapp polls 创建 app
   Vim polls/models.py
       继承 django.db models.Model
       实现对应的配置接口




                                             5/20
TIPS
   Projects vs. apps
       A project can contain multiple apps.
       An app can be in multiple projects.
   Philosophy
       A model is the single, definitive source of data about your
        data.
       It contains the essential fields and behaviors of the data
        you're storing.
       Django follows the DRY Principle.
       The goal is to define your data model in one place and
        automatically derive things from it.


                                                                  6/20
Activating models
   Create a database schema
    (CREATE TABLE statements) for this app.
   Create a Python database-access API for
    accessing Poll and Choice objects.
   settings.py: INSTALLED_APPS 加
    上  'mysite.polls'
   python manage.py sql polls
   python manage.py syncdb

                                              7/20
Other cmds on DB
   python manage.py sql polls 建立模型
   python manage.py validate 验证 models 错
    误
   python manage.py sqlcustom polls 自定义
    SQL
   python manage.py sqlindexes polls 建立索
    引 SQL
   python manage.py sqlall polls 全部  sql,
    sqlcustom, 和  sqlindexes
   python manage.py dbshell 数据库控制台 8/20
Playing with the API
   python manage.py shell 自动导入 mysite 环
    境
   Poll.objects.all()
   …




                                       9/20
Activate the admin site
   INSTALLED_APPS: ‘django.contrib.admin’
   python manage.py syncdb 新 APP 更新 DB
   vim urls.py 建立 url 映射
   python manage.py runserver 开启服务器
   manage.py createsuperuser 创建新用户
   [polls]# vim admin.py 在 polls 添加 admin.py
       from mysite.polls.models import Poll
       from django.contrib import admin

       admin.site.register(Poll)

   …more admin ops

                                                10/20
View
   Views in Poll
       ‘archive’ page
       ‘detail’ page
       ‘results’ page
       Vote action
   In Django, each view is a py function




                                            11/20
Design URLs
   Settings: ROOT_URLCONF = ‘mysite.urls’ 表示
    mysite/urls.py
   Find variable named urlpatterns in ROOT_URLCONF
        (regular expression, Python callback function [, optional dictionary])
   Example:
        (r'^polls/(?P<poll_id>d+)/$', 'mysite.polls.views.detail'),
              (?P<poll_id>) 定义一个命名组; (?P=name) 则是对命名组
               的逆向引用
               d+ 对应的正则表达式
        /polls/23/
              detail(request=<HttpRequest object>, poll_id=‘23’ )
   Note : Django Will not search GET and POST parameters



                                                                                  12/20
First View

   t = loader.get_template('polls/index.html')
   c = Context({ 'latest_poll_list':
    latest_poll_list, })
   HttpResponse(t.render(c))
   A shortcut:
       render_to_response(strTemplate , dicContex
        t)

    PBL : ObjectDoesNotExist    为什么替换为
    Http404
                                                  13/20
Use the template system
   The Django template language
       http://docs.djangoproject.com/en/dev/topics/templates/




                                                      14/20
Decoupling the URLconfs
   cp urls.py polls/
   去掉 ^polls/ 的部分和 admin 的部分




                                15/20
POST GET
   request.POST['choice']
    request.GET
   '/polls/3/results/' ==
       reverse(‘mysite.polls.views.results’, args=(p.id,) )




                                                         16/20
Model 的自动转化
   插入对象
       mtable =MainTable(word_number="12.250")
       mtable.save() # 此刻 word_number 会转化成
        12.250 存储到数据库中
   Python 中除了 '' 、 "" 、 0 、 () 、 [] 、
    {} 、 None 为 False 之外,其他的都是
    True 。
PBL——Model
   Model 建立的流程是怎样的呢?
   Model 映射到数据库表时,如何处理外键?
   Model 中的数据只能是基本的数据库类型么?
   Model 按照数据库类型来声明会约束其应用么?会有不方
    便么?
   我们项目如何在其之上开发出 Graph Database 的应用?
   如果仅仅使用映射表动态添加属性,性能会怎样?
   常用的场景和操作有哪些?
       全部属性检索
       单个属性检索
       组合属性检索
   Django 如何支持表连接操作?

                                    18/20
PBL——View
   怎样获取 Get 和 Post
   怎样使用 Session 和 Cookie




                            19/20
PBL——Template
   模板语言怎样使用?
   循环,分支
   安全性:跨站,注入?




                 20/20
PBL——Python 语言
   Meta-Programming




                       21/20
Thank you!



             22/20

Contenu connexe

Tendances

Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterBo-Yi Wu
 
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.xIntroduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.xBo-Yi Wu
 
Spring4.x + hibernate4.x_配置详解
Spring4.x + hibernate4.x_配置详解Spring4.x + hibernate4.x_配置详解
Spring4.x + hibernate4.x_配置详解zany_hui
 
不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会Joseph Chiang
 
Parse, cloud code 介紹
Parse, cloud code 介紹Parse, cloud code 介紹
Parse, cloud code 介紹wantingj
 
CodeIgniter 2.0.X
CodeIgniter 2.0.XCodeIgniter 2.0.X
CodeIgniter 2.0.XBo-Yi Wu
 
JCConf2015: groovy to gradle
 JCConf2015: groovy to gradle JCConf2015: groovy to gradle
JCConf2015: groovy to gradleChing Yi Chan
 
Javascript autoload
Javascript autoloadJavascript autoload
Javascript autoloadjay li
 
Page Object in XCUITest
Page Object in XCUITestPage Object in XCUITest
Page Object in XCUITestJz Chang
 
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile ServicesKuo-Chun Su
 
张所勇:前端开发工具推荐
张所勇:前端开发工具推荐张所勇:前端开发工具推荐
张所勇:前端开发工具推荐zhangsuoyong
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big DataKuo-Chun Su
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7javatwo2011
 
基于原型的JavaScript面向对象编程
基于原型的JavaScript面向对象编程基于原型的JavaScript面向对象编程
基于原型的JavaScript面向对象编程zhangdaiping
 
JavaScript Code Quality
JavaScript Code QualityJavaScript Code Quality
JavaScript Code QualityJoseph Chiang
 
Django development
Django developmentDjango development
Django developmentloveyudu
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向Shengyou Fan
 

Tendances (18)

Phpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniterPhpconf 2011 introduction_to_codeigniter
Phpconf 2011 introduction_to_codeigniter
 
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.xIntroduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
 
Spring4.x + hibernate4.x_配置详解
Spring4.x + hibernate4.x_配置详解Spring4.x + hibernate4.x_配置详解
Spring4.x + hibernate4.x_配置详解
 
不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会不断归零的前端人生 - 2016 中国软件开发者大会
不断归零的前端人生 - 2016 中国软件开发者大会
 
Parse, cloud code 介紹
Parse, cloud code 介紹Parse, cloud code 介紹
Parse, cloud code 介紹
 
Node way
Node wayNode way
Node way
 
CodeIgniter 2.0.X
CodeIgniter 2.0.XCodeIgniter 2.0.X
CodeIgniter 2.0.X
 
JCConf2015: groovy to gradle
 JCConf2015: groovy to gradle JCConf2015: groovy to gradle
JCConf2015: groovy to gradle
 
Javascript autoload
Javascript autoloadJavascript autoload
Javascript autoload
 
Page Object in XCUITest
Page Object in XCUITestPage Object in XCUITest
Page Object in XCUITest
 
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
 
张所勇:前端开发工具推荐
张所勇:前端开发工具推荐张所勇:前端开发工具推荐
张所勇:前端开发工具推荐
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big Data
 
千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7千呼萬喚始出來的Java SE 7
千呼萬喚始出來的Java SE 7
 
基于原型的JavaScript面向对象编程
基于原型的JavaScript面向对象编程基于原型的JavaScript面向对象编程
基于原型的JavaScript面向对象编程
 
JavaScript Code Quality
JavaScript Code QualityJavaScript Code Quality
JavaScript Code Quality
 
Django development
Django developmentDjango development
Django development
 
PHP 語法基礎與物件導向
PHP 語法基礎與物件導向PHP 語法基礎與物件導向
PHP 語法基礎與物件導向
 

Similaire à Django

Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文Guo Albert
 
旺铺前端设计和实现
旺铺前端设计和实现旺铺前端设计和实现
旺铺前端设计和实现hua qiu
 
Django敏捷开发 刘天斯
Django敏捷开发 刘天斯Django敏捷开发 刘天斯
Django敏捷开发 刘天斯liuts
 
HTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 appHTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 appBen Lue
 
Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1modou li
 
HTML5概览
HTML5概览HTML5概览
HTML5概览Adam Lu
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdfssuserd6c7621
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)FLASH开发者交流会
 
Asp.net mvc 培训
Asp.net mvc 培训Asp.net mvc 培训
Asp.net mvc 培训lotusprince
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)Wei Sun
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027Wei Sun
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVCjeffz
 
Google App Engine Devfest 200810 External
Google App Engine Devfest 200810 ExternalGoogle App Engine Devfest 200810 External
Google App Engine Devfest 200810 Externaljunyu
 
Django讲座
Django讲座Django讲座
Django讲座Qing Feng
 
Magento页面载入的执行流程
Magento页面载入的执行流程Magento页面载入的执行流程
Magento页面载入的执行流程Sim Jiason
 
前端MVC之backbone
前端MVC之backbone前端MVC之backbone
前端MVC之backboneJerry Xie
 
Django入门
Django入门Django入门
Django入门oikomi
 
Open Api&Sip
Open Api&SipOpen Api&Sip
Open Api&Sipcenwenchu
 

Similaire à Django (20)

Spring 2.x 中文
Spring 2.x 中文Spring 2.x 中文
Spring 2.x 中文
 
旺铺前端设计和实现
旺铺前端设计和实现旺铺前端设计和实现
旺铺前端设计和实现
 
Django敏捷开发 刘天斯
Django敏捷开发 刘天斯Django敏捷开发 刘天斯
Django敏捷开发 刘天斯
 
HTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 appHTML+COIMOTION 開發跨平台 app
HTML+COIMOTION 開發跨平台 app
 
Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1Uliweb cheat sheet_0.1
Uliweb cheat sheet_0.1
 
HTML5概览
HTML5概览HTML5概览
HTML5概览
 
4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf4. Go 工程化实践-0124-v2.pdf
4. Go 工程化实践-0124-v2.pdf
 
Django step0
Django step0Django step0
Django step0
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)
 
Asp.net mvc 培训
Asp.net mvc 培训Asp.net mvc 培训
Asp.net mvc 培训
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVC
 
Google App Engine Devfest 200810 External
Google App Engine Devfest 200810 ExternalGoogle App Engine Devfest 200810 External
Google App Engine Devfest 200810 External
 
Django讲座
Django讲座Django讲座
Django讲座
 
Reply
ReplyReply
Reply
 
Magento页面载入的执行流程
Magento页面载入的执行流程Magento页面载入的执行流程
Magento页面载入的执行流程
 
前端MVC之backbone
前端MVC之backbone前端MVC之backbone
前端MVC之backbone
 
Django入门
Django入门Django入门
Django入门
 
Open Api&Sip
Open Api&SipOpen Api&Sip
Open Api&Sip
 

Plus de Tao He

Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Tao He
 
A software fault localization technique based on program mutations
A software fault localization technique based on program mutationsA software fault localization technique based on program mutations
A software fault localization technique based on program mutationsTao He
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvmTao He
 
Testing survey
Testing surveyTesting survey
Testing surveyTao He
 
Testing survey by_directions
Testing survey by_directionsTesting survey by_directions
Testing survey by_directionsTao He
 
Smart debugger
Smart debuggerSmart debugger
Smart debuggerTao He
 
Mutation testing
Mutation testingMutation testing
Mutation testingTao He
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4Tao He
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述Tao He
 
Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Tao He
 
Testing group’s work on fault localization
Testing group’s work on fault localizationTesting group’s work on fault localization
Testing group’s work on fault localizationTao He
 
Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Tao He
 
Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Tao He
 
Semantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamSemantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamTao He
 
Problems
ProblemsProblems
ProblemsTao He
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testingTao He
 
Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Tao He
 
Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Tao He
 

Plus de Tao He (18)

Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念Java 并发编程笔记:01. 并行与并发 —— 概念
Java 并发编程笔记:01. 并行与并发 —— 概念
 
A software fault localization technique based on program mutations
A software fault localization technique based on program mutationsA software fault localization technique based on program mutations
A software fault localization technique based on program mutations
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvm
 
Testing survey
Testing surveyTesting survey
Testing survey
 
Testing survey by_directions
Testing survey by_directionsTesting survey by_directions
Testing survey by_directions
 
Smart debugger
Smart debuggerSmart debugger
Smart debugger
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4C语言benchmark覆盖信息收集总结4
C语言benchmark覆盖信息收集总结4
 
基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述基于覆盖信息的软件错误定位技术综述
基于覆盖信息的软件错误定位技术综述
 
Java覆盖信息收集工具比较
Java覆盖信息收集工具比较Java覆盖信息收集工具比较
Java覆盖信息收集工具比较
 
Testing group’s work on fault localization
Testing group’s work on fault localizationTesting group’s work on fault localization
Testing group’s work on fault localization
 
Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0Muffler a tool using mutation to facilitate fault localization 2.0
Muffler a tool using mutation to facilitate fault localization 2.0
 
Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3Muffler a tool using mutation to facilitate fault localization 2.3
Muffler a tool using mutation to facilitate fault localization 2.3
 
Semantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti SpamSemantic Parsing in Bayesian Anti Spam
Semantic Parsing in Bayesian Anti Spam
 
Problems
ProblemsProblems
Problems
 
A survey of software testing
A survey of software testingA survey of software testing
A survey of software testing
 
Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...Cleansing test suites from coincidental correctness to enhance falut localiza...
Cleansing test suites from coincidental correctness to enhance falut localiza...
 
Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?Concrete meta research - how to collect, manage, and read papers?
Concrete meta research - how to collect, manage, and read papers?
 

Django

  • 1. Django Tao He elfinhe@gmail.com @SELAB, SYSU 1/20
  • 2. Install  Install Python  Set up a database  Install Django  tar xzvf Django-NNN.tar.gz  sudo python setup.py install http://docs.djangoproject.com/en/dev/intro/install 2/20
  • 3. Writing your first Django app  import django  django-admin.py startproject mysite  mysite/  __init__.py  manage.py 对 Django 进行脚本管理  settings.py 项目配置  urls.py URL 分配器配置  python manage.py runserver 启动开发服务器  wget -O- -q http://127.0.0.1:8000/ 测试服务器  python manage.py runserver 192.168.128.141:80 3/20
  • 4. Database setup  vim settings.py  'ENGINE': 'django.db.backends.sqlite3‘  ‘NAME’:’mysite’  python manage.py syncdb 4/20
  • 5. Creating models  python manage.py startapp polls 创建 app  Vim polls/models.py  继承 django.db models.Model  实现对应的配置接口 5/20
  • 6. TIPS  Projects vs. apps  A project can contain multiple apps.  An app can be in multiple projects.  Philosophy  A model is the single, definitive source of data about your data.  It contains the essential fields and behaviors of the data you're storing.  Django follows the DRY Principle.  The goal is to define your data model in one place and automatically derive things from it. 6/20
  • 7. Activating models  Create a database schema (CREATE TABLE statements) for this app.  Create a Python database-access API for accessing Poll and Choice objects.  settings.py: INSTALLED_APPS 加 上  'mysite.polls'  python manage.py sql polls  python manage.py syncdb 7/20
  • 8. Other cmds on DB  python manage.py sql polls 建立模型  python manage.py validate 验证 models 错 误  python manage.py sqlcustom polls 自定义 SQL  python manage.py sqlindexes polls 建立索 引 SQL  python manage.py sqlall polls 全部  sql, sqlcustom, 和  sqlindexes  python manage.py dbshell 数据库控制台 8/20
  • 9. Playing with the API  python manage.py shell 自动导入 mysite 环 境  Poll.objects.all()  … 9/20
  • 10. Activate the admin site  INSTALLED_APPS: ‘django.contrib.admin’  python manage.py syncdb 新 APP 更新 DB  vim urls.py 建立 url 映射  python manage.py runserver 开启服务器  manage.py createsuperuser 创建新用户  [polls]# vim admin.py 在 polls 添加 admin.py  from mysite.polls.models import Poll  from django.contrib import admin  admin.site.register(Poll)  …more admin ops 10/20
  • 11. View  Views in Poll  ‘archive’ page  ‘detail’ page  ‘results’ page  Vote action  In Django, each view is a py function 11/20
  • 12. Design URLs  Settings: ROOT_URLCONF = ‘mysite.urls’ 表示 mysite/urls.py  Find variable named urlpatterns in ROOT_URLCONF  (regular expression, Python callback function [, optional dictionary])  Example:  (r'^polls/(?P<poll_id>d+)/$', 'mysite.polls.views.detail'),  (?P<poll_id>) 定义一个命名组; (?P=name) 则是对命名组 的逆向引用  d+ 对应的正则表达式  /polls/23/  detail(request=<HttpRequest object>, poll_id=‘23’ )  Note : Django Will not search GET and POST parameters 12/20
  • 13. First View  t = loader.get_template('polls/index.html')  c = Context({ 'latest_poll_list': latest_poll_list, })  HttpResponse(t.render(c))  A shortcut:  render_to_response(strTemplate , dicContex t)  PBL : ObjectDoesNotExist 为什么替换为 Http404 13/20
  • 14. Use the template system  The Django template language  http://docs.djangoproject.com/en/dev/topics/templates/ 14/20
  • 15. Decoupling the URLconfs  cp urls.py polls/  去掉 ^polls/ 的部分和 admin 的部分 15/20
  • 16. POST GET  request.POST['choice']  request.GET  '/polls/3/results/' ==  reverse(‘mysite.polls.views.results’, args=(p.id,) ) 16/20
  • 17. Model 的自动转化  插入对象  mtable =MainTable(word_number="12.250")  mtable.save() # 此刻 word_number 会转化成 12.250 存储到数据库中  Python 中除了 '' 、 "" 、 0 、 () 、 [] 、 {} 、 None 为 False 之外,其他的都是 True 。
  • 18. PBL——Model  Model 建立的流程是怎样的呢?  Model 映射到数据库表时,如何处理外键?  Model 中的数据只能是基本的数据库类型么?  Model 按照数据库类型来声明会约束其应用么?会有不方 便么?  我们项目如何在其之上开发出 Graph Database 的应用?  如果仅仅使用映射表动态添加属性,性能会怎样?  常用的场景和操作有哪些?  全部属性检索  单个属性检索  组合属性检索  Django 如何支持表连接操作? 18/20
  • 19. PBL——View  怎样获取 Get 和 Post  怎样使用 Session 和 Cookie 19/20
  • 20. PBL——Template  模板语言怎样使用?  循环,分支  安全性:跨站,注入? 20/20
  • 21. PBL——Python 语言  Meta-Programming 21/20
  • 22. Thank you! 22/20