SlideShare a Scribd company logo
1 of 38
The Django Web Application
        Framework


                     zhixiong.hong
                       2009.3.26
Outline
 Overview
 Architecture
 Modules
 Example
 Links
Outline
 Overview
 Architecture
 Example
 Modules
 Links
Web Application Framework
 Define
  “A software framework that is designed to support the development of
     dynamic website, Web applications and Web services”(from wikipedia)
 The ideal framework
   Clean URLs
   Loosely coupled components
   Designer-friendly templates
   As little code as possible
   Really fast development
Web Application Framework(cont..)
 Ruby
  Ruby on Rails (famous, beauty)
 Python
  Django, TurboGears, Pylons, Zope, Quixote,web2py(simple)
 PHP
  CakePHP, CodeIgniter, PRADO, ThinkPHP,QeePHP (poor performance)
 Others
  Apache, J2EE, .NET...(complex)
Web Application Framework(cont..)
Comparsion
What a Django
 “Django is a high-level Python web framework that
  encourages rapid development and clean, pragmatic
  design.”
 Primary Focus
   Dynamic and database driven website
   Content based websites
Django History
 Named after famous Guitarist “Django Reinhardt”
 Developed by Adrian Holovaty & Jacob Kaplan-moss
 Open sourced in 2005
 1.0 Version released Sep.3 2008, now 1.1 Beta
Why Use Django
 Lets you divide code modules into logical groups to make it flexible
  to change
   MVC design pattern (MVT)
 Provides auto generated web admin to ease the website
  administration
 Provides pre-packaged API for common user tasks
 Provides you template system to define HTML template for your
  web pages to avoid code duplication
   DRY Principle
 Allows you to define what URL be for a given Function
   Loosely Coupled Principle
 Allows you to separate business logic from the HTML
   Separation of concerns
 Everything is in python (schema/settings)
Outline
 Overview
 Architecture
 Modules
 Example
 Links
Django as an MVC Design Pattern
  MVT Architecture:
   Models
    Describes your data structure/database schema
   Views
     Controls what a user sees
   Templates
     How a user sees it
   Controller
     The Django Framework
     URL dispatcher
Architecture Diagram

                    Brower



         Template              URL dispatcher



                     View



                     Model



                    DataBase
Model

                   Brower



        Template              URL dispatcher



                    View



                    Model



                   DataBase
Model Overview
SQL Free
ORM
Relations
API
Model

  class Category(models.Model):
       name = models.CharField(max_length=200)
       slug = models.SlugField(unique=True)



  class Entry(models.Model):
       title = models.CharField(max_length=200)
       slug = models.SlugField(unique=True)
       body = models.TextField()
       data = models.DateTimeField(default=datetime.now)
       categories = models.ManyToManyField(Category)


  python manage.py syncdb
Model API
  >>> category = Category(slug='django', name='Django')
  >>> category.save()
  >>> print category.name
  u'Django'

  >>> categories = Category.objects.all()
  >>> categories = Category.objects.filter(slug='django')
  >>> categories
  [<Category: Category object>]

  >>> entry = Entry(slug='welcome', title='Welcome', body='')
  >>> entry.save()
  >>> entry.categories.add( category[0] )
  >>> print entry.categories.all()
  [<Category: Category object>]
View

                  Brower



       Template              URL dispatcher



                   View



                   Model



                  DataBase
View

  def entry_list(request):
      entries = Ebtry.objects.all()[:5]
      return render_to_response('list.html', {'entries': entries})



  def entry_details(request, slug):
       entry = get_object_or_404(Entry, slug = slug)
       return render_to_response('details.html', {'entry': entry})
Template

                      Brower



           Template              URL dispatcher



                       View



                       Model



                      DataBase
Template Syntax
 {{ variables }}, {% tags %}, filters               (list.html)

  <html>
      <head>
      <title>My Blog</title>
      </head>
      <body>
      {% for entry in entries %}
      <h1>{{ entry.title|upper }}</h1>
      {{ entry.body }}<br/>
      Published {{ entry.data|date:quot;d F Yquot; }},
      <a href=”{{ entry.get_absolute_url }}”>link</a>.
      {% endfor %}
      </body>
  </html>
Tag and Filter
 Build in Filters and Tags
 Custom tag and filter libraries
   Put logic in tags
  {% load comments %}
  <h1>{{ entry.title|upper }}</h1>
  {{ entry.body }}<br/>
  Published {{ entry.data|date:quot;d F Yquot; }},
  <a href=”{{ entry.get_absolute_url }}”>link</a>.
  <h3>评论: </h3>
  {% get_comment_list for entry as comment_list %}
  {% for comment in comment_list %}
       {{ comment.content }}
  {% endfor %}
Template Inheritance
 base.html                      index.html
  <html>
      <head>
      <title>
                                {% extend “base.html” %}
            {% block title %}
                                {% block title %}
            {% endblock %}
                                     Main page
      </title>
                                {% endblock %}
      </head>
                                {% block body %}
      <body>
                                     Content
            {% block body %}
                                {% endblock %}
            {% endblock %}
      </body>
  </html>
URL Dispatcher

                   Brower



        Template              URL Dispatcher



                    View



                    Model



                   DataBase
URL Dispatcher

  urlpatterns = patterns('',
  #http://jianghu.leyubox.com/articles/
  ((r'^articles/$', ‘article.views.index'), )

  #http://jianghu.leyubox.com/articles/2003/
  (r'^articles/(?P<year>d{4})/$', ‘article.views.year_archive'),

  # http://jianghu.leyubox.com/articles/2003/ 12/
  (r'^articles/(?P<year>d{4})/(?P<month>d{2})/$',
  'article.views.month_archive'),

  # http://jianghu.leyubox.com/articles/2003/ 12/3
  (r'^articles/(?P<year>d{4})/(?P<month>d{2})/(?P<day>d+)/$',
  'article..views.article_detail'), )
Outline
 Overview
 Architecture
 Modules
 Example
 Links
Modules
 Form
 Adminstration interface
 Custom Middleware
 Caching
 Signals
 Comments system
 More...
Modules:Form

  class ContactForm(forms.Form):
       subject = forms.CharField(max_length=100)
       message = forms.CharField(widget=forms.Textarea)
       sender = forms.EmailField()
       cc_myself = forms.BooleanField(required=False)



  <form action=quot;/contact/quot; method=quot;POSTquot;>
       {{ form.as_table}}
       <input type=quot;submitquot; value=quot;Submitquot; />
  </form>
Modules:Adminstration interface
Modules: Custom Middleware
     chain of processes


request                                                         response
           Common       Session     Authentication     Profile
          Middleware   Middleware    Middleware      Middleware
Modules: Caching


   Memcached     Database   Filesystem     Local-memory        Dummy


                            BaseCache



                                                          template caching
                                   Per-View Caching
      Per-Site Caching
Modules:More...
 Sessions
 Authentication system
 Internationalization and localization
 Syndication feeds(RSS/Atom)
 E-mail(sending)
 Pagination
 Signals
Outline
 Overview
 Architecture
 Modules
 Example
 Links
Example
 django_admin startproject leyubbs
 modify setting.py
   set database options
   append admin app: django.contrib.admin
 python manager.py syncdb
 python manager.py runserver
 modify urls.py, append /admin path
Example(cont...)
 python manager.py startapp article
 add a model
 python manager.py syncdb
 explore admin page
 inset a record in adminstration interface
 add a veiw function
 add a url
Outline
 Overview
 Architecture
 Modules
 Example
 Links
Links: Who Use
Links: Resource
 http://www.djangoproject.com/
  For more information (Documentation,Download and News)

 http://www.djangobook.com/
  A Good book to learn Django

 http://www.djangopluggables.com
  A lot of Django Pluggables available online Explore at

 http://www.pinaxproject.com/
  Community Development
Thanks (Q&A)

More Related Content

What's hot

Seo cheat sheet_2-2013
Seo cheat sheet_2-2013Seo cheat sheet_2-2013
Seo cheat sheet_2-2013
ekkarthik
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
SEONGTAEK OH
 

What's hot (18)

Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
[PyConZA 2017] Web Scraping: Unleash your Internet Viking
[PyConZA 2017] Web Scraping: Unleash your Internet Viking[PyConZA 2017] Web Scraping: Unleash your Internet Viking
[PyConZA 2017] Web Scraping: Unleash your Internet Viking
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Seo cheat sheet_2-2013
Seo cheat sheet_2-2013Seo cheat sheet_2-2013
Seo cheat sheet_2-2013
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
Html tags describe in bangla
Html tags describe in banglaHtml tags describe in bangla
Html tags describe in bangla
 
Html bangla
Html banglaHtml bangla
Html bangla
 
Bangla html
Bangla htmlBangla html
Bangla html
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用
 
Django Templates
Django TemplatesDjango Templates
Django Templates
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web Components
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Django Bogotá. CBV
Django Bogotá. CBVDjango Bogotá. CBV
Django Bogotá. CBV
 
Ch9 .Best Practices for Class-Based Views
Ch9 .Best Practices  for  Class-Based ViewsCh9 .Best Practices  for  Class-Based Views
Ch9 .Best Practices for Class-Based Views
 
Html server control - ASP. NET with c#
Html server control - ASP. NET with c#Html server control - ASP. NET with c#
Html server control - ASP. NET with c#
 
Seo Cheat Sheet
Seo Cheat SheetSeo Cheat Sheet
Seo Cheat Sheet
 

Similar to The Django Web Application Framework 2

Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
Kevin Wu
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
salemsg
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 

Similar to The Django Web Application Framework 2 (20)

Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVC
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

The Django Web Application Framework 2

  • 1. The Django Web Application Framework zhixiong.hong 2009.3.26
  • 2. Outline  Overview  Architecture  Modules  Example  Links
  • 3. Outline  Overview  Architecture  Example  Modules  Links
  • 4. Web Application Framework  Define “A software framework that is designed to support the development of dynamic website, Web applications and Web services”(from wikipedia)  The ideal framework  Clean URLs  Loosely coupled components  Designer-friendly templates  As little code as possible  Really fast development
  • 5. Web Application Framework(cont..)  Ruby Ruby on Rails (famous, beauty)  Python Django, TurboGears, Pylons, Zope, Quixote,web2py(simple)  PHP CakePHP, CodeIgniter, PRADO, ThinkPHP,QeePHP (poor performance)  Others Apache, J2EE, .NET...(complex)
  • 7. What a Django  “Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.”  Primary Focus  Dynamic and database driven website  Content based websites
  • 8. Django History  Named after famous Guitarist “Django Reinhardt”  Developed by Adrian Holovaty & Jacob Kaplan-moss  Open sourced in 2005  1.0 Version released Sep.3 2008, now 1.1 Beta
  • 9. Why Use Django  Lets you divide code modules into logical groups to make it flexible to change MVC design pattern (MVT)  Provides auto generated web admin to ease the website administration  Provides pre-packaged API for common user tasks  Provides you template system to define HTML template for your web pages to avoid code duplication DRY Principle  Allows you to define what URL be for a given Function Loosely Coupled Principle  Allows you to separate business logic from the HTML Separation of concerns  Everything is in python (schema/settings)
  • 10. Outline  Overview  Architecture  Modules  Example  Links
  • 11. Django as an MVC Design Pattern MVT Architecture:  Models Describes your data structure/database schema  Views Controls what a user sees  Templates How a user sees it  Controller The Django Framework URL dispatcher
  • 12. Architecture Diagram Brower Template URL dispatcher View Model DataBase
  • 13. Model Brower Template URL dispatcher View Model DataBase
  • 15. Model class Category(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(unique=True) class Entry(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique=True) body = models.TextField() data = models.DateTimeField(default=datetime.now) categories = models.ManyToManyField(Category) python manage.py syncdb
  • 16. Model API >>> category = Category(slug='django', name='Django') >>> category.save() >>> print category.name u'Django' >>> categories = Category.objects.all() >>> categories = Category.objects.filter(slug='django') >>> categories [<Category: Category object>] >>> entry = Entry(slug='welcome', title='Welcome', body='') >>> entry.save() >>> entry.categories.add( category[0] ) >>> print entry.categories.all() [<Category: Category object>]
  • 17. View Brower Template URL dispatcher View Model DataBase
  • 18. View def entry_list(request): entries = Ebtry.objects.all()[:5] return render_to_response('list.html', {'entries': entries}) def entry_details(request, slug): entry = get_object_or_404(Entry, slug = slug) return render_to_response('details.html', {'entry': entry})
  • 19. Template Brower Template URL dispatcher View Model DataBase
  • 20. Template Syntax  {{ variables }}, {% tags %}, filters (list.html) <html> <head> <title>My Blog</title> </head> <body> {% for entry in entries %} <h1>{{ entry.title|upper }}</h1> {{ entry.body }}<br/> Published {{ entry.data|date:quot;d F Yquot; }}, <a href=”{{ entry.get_absolute_url }}”>link</a>. {% endfor %} </body> </html>
  • 21. Tag and Filter  Build in Filters and Tags  Custom tag and filter libraries Put logic in tags {% load comments %} <h1>{{ entry.title|upper }}</h1> {{ entry.body }}<br/> Published {{ entry.data|date:quot;d F Yquot; }}, <a href=”{{ entry.get_absolute_url }}”>link</a>. <h3>评论: </h3> {% get_comment_list for entry as comment_list %} {% for comment in comment_list %} {{ comment.content }} {% endfor %}
  • 22. Template Inheritance base.html index.html <html> <head> <title> {% extend “base.html” %} {% block title %} {% block title %} {% endblock %} Main page </title> {% endblock %} </head> {% block body %} <body> Content {% block body %} {% endblock %} {% endblock %} </body> </html>
  • 23. URL Dispatcher Brower Template URL Dispatcher View Model DataBase
  • 24. URL Dispatcher urlpatterns = patterns('', #http://jianghu.leyubox.com/articles/ ((r'^articles/$', ‘article.views.index'), ) #http://jianghu.leyubox.com/articles/2003/ (r'^articles/(?P<year>d{4})/$', ‘article.views.year_archive'), # http://jianghu.leyubox.com/articles/2003/ 12/ (r'^articles/(?P<year>d{4})/(?P<month>d{2})/$', 'article.views.month_archive'), # http://jianghu.leyubox.com/articles/2003/ 12/3 (r'^articles/(?P<year>d{4})/(?P<month>d{2})/(?P<day>d+)/$', 'article..views.article_detail'), )
  • 25. Outline  Overview  Architecture  Modules  Example  Links
  • 26. Modules  Form  Adminstration interface  Custom Middleware  Caching  Signals  Comments system  More...
  • 27. Modules:Form class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField(widget=forms.Textarea) sender = forms.EmailField() cc_myself = forms.BooleanField(required=False) <form action=quot;/contact/quot; method=quot;POSTquot;> {{ form.as_table}} <input type=quot;submitquot; value=quot;Submitquot; /> </form>
  • 29. Modules: Custom Middleware chain of processes request response Common Session Authentication Profile Middleware Middleware Middleware Middleware
  • 30. Modules: Caching Memcached Database Filesystem Local-memory Dummy BaseCache template caching Per-View Caching Per-Site Caching
  • 31. Modules:More...  Sessions  Authentication system  Internationalization and localization  Syndication feeds(RSS/Atom)  E-mail(sending)  Pagination  Signals
  • 32. Outline  Overview  Architecture  Modules  Example  Links
  • 33. Example  django_admin startproject leyubbs  modify setting.py  set database options  append admin app: django.contrib.admin  python manager.py syncdb  python manager.py runserver  modify urls.py, append /admin path
  • 34. Example(cont...)  python manager.py startapp article  add a model  python manager.py syncdb  explore admin page  inset a record in adminstration interface  add a veiw function  add a url
  • 35. Outline  Overview  Architecture  Modules  Example  Links
  • 37. Links: Resource  http://www.djangoproject.com/ For more information (Documentation,Download and News)  http://www.djangobook.com/ A Good book to learn Django  http://www.djangopluggables.com A lot of Django Pluggables available online Explore at  http://www.pinaxproject.com/ Community Development