SlideShare ist ein Scribd-Unternehmen logo
1 von 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)

Weitere ähnliche Inhalte

Was ist angesagt?

Gordian Knot Presentation (Help Network)
Gordian Knot Presentation (Help Network)Gordian Knot Presentation (Help Network)
Gordian Knot Presentation (Help Network)Jim Osowski
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsBG Java EE Course
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
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 IslandsBastian Hofmann
 
[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 VikingAndrew Collier
 
Html 5 in a big nutshell
Html 5 in a big nutshellHtml 5 in a big nutshell
Html 5 in a big nutshellLennart Schoors
 
Seo cheat sheet_2-2013
Seo cheat sheet_2-2013Seo cheat sheet_2-2013
Seo cheat sheet_2-2013ekkarthik
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
Templates
TemplatesTemplates
Templatessoon
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application StructureSEONGTAEK OH
 
Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用LearningTech
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowPrabhdeep Singh
 
Django Templates
Django TemplatesDjango Templates
Django TemplatesWilly Liu
 
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 ComponentsRachael L Moore
 

Was ist angesagt? (18)

Gordian Knot Presentation (Help Network)
Gordian Knot Presentation (Help Network)Gordian Knot Presentation (Help Network)
Gordian Knot Presentation (Help Network)
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
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
 
Html 5 in a big nutshell
Html 5 in a big nutshellHtml 5 in a big nutshell
Html 5 in a big nutshell
 
Seo cheat sheet_2-2013
Seo cheat sheet_2-2013Seo cheat sheet_2-2013
Seo cheat sheet_2-2013
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
Templates
TemplatesTemplates
Templates
 
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, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用
 
HTL(Sightly) - All you need to know
HTL(Sightly) - All you need to knowHTL(Sightly) - All you need to know
HTL(Sightly) - All you need to know
 
Html bangla
Html banglaHtml bangla
Html bangla
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Bangla html
Bangla htmlBangla html
Bangla html
 
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
 

Ähnlich wie 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 Phpfunkatron
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVCAlan Dean
 
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 prazosIgor Sobreira
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introductionTomi Juhola
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
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!Eric Palakovich Carr
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsJohn Brunswick
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigWake Liu
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxsalemsg
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NETgoodfriday
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Guillaume Laforge
 
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 EngineYared Ayalew
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
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 Appplicationolegmmiller
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 

Ähnlich wie 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
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007Grails Introduction - IJTC 2007
Grails Introduction - IJTC 2007
 
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
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
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
 
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
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

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