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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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