SlideShare a Scribd company logo
1 of 26
Download to read offline
What is Django?
        Features
     References




Introducing Django

      Horst Gutmann


   September 30, 2007




                        1 / 34
What is Django?
                                Features
                             References


Disclaimer




   I’m not of the developers of Django but merely a user who likes
   what he’s seen. My experience is limited to small sites that can be
   comfortably run on a shared host such as Dreamhost.
   And I want to apologize for the noise my laptop is probably going
   to make during the presentation ;-)




                                                                         2 / 34
What is Django?
                                                   General
                                        Features
                                                   What do you need?
                                     References


What is Django?

                  Django is a high-level Python Web framework that
              encourages rapid development and clean, pragmatic
              design.
   [1]
              Model-View-Controller for the Web
              Written in Python
              Explicit instead of implicit
              Developed for the Lawrence Journal-World1 newspaper in
              Kansas


         1
             http://www2.ljworld.com/
                                                                       3 / 34
What is Django?
                                    General
                         Features
                                    What do you need?
                      References


What is an MVC web framework?




  Abstraction




                                                        5 / 34
What is Django?
                                        General
                             Features
                                        What do you need?
                          References


Abstract HTTP




     Do we really want to manually parse HTTP requests?
     Frameworks should automate things like header creation
     Allow easy cookie handling




                                                              6 / 34
What is Django?
                                               General
                                    Features
                                               What do you need?
                                 References


Abstract database calls



   Page . o b j e c t s . g e t ( i d =10)
   instead of
   SELECT ∗ FROM page WHERE i d =10;
   Not to mention keeping it backend independent and mapping the
   resultset to objects in the used programming language.




                                                                   8 / 34
What is Django?
                                                  General
                                       Features
                                                  What do you need?
                                    References


Dispatch URLs



        URLs or URL patterns should be mapped to functions or
        objects
        ... that then create the output.

   u r l p a t t e r n s += p a t t e r n s ( ’ ’ ,
           u r l ( ’ ˆ$ ’ , ’ v i e w s . i n d e x ’ ) ,
   )




                                                                      10 / 34
What is Django?
                                          General
                               Features
                                          What do you need?
                            References


MVC or MVT?


  Django uses a little bit different naming for the
  Model-View-Controller pattern.
       Models abstract the used data by defining classes for them
              and storing them in relational tables.
        Views take the job of the controllers in MVC and basically
              define, what the user gets to see. Functions, not
              classes here.
    Templates define how the users see the view




                                                                     11 / 34
What is Django?
                                           General
                                Features
                                           What do you need?
                             References


Projects and Applications



        Project A project is for example your whole website. Here
                you store your central configuration and general
                templates and images (just as an example).
   Applications are where you store the actual functionality. For
                example a weblog would be an application. An
                account system would be an application ...
   Applications are a simple way to share common functionality
   between various projects.




                                                                    12 / 34
What is Django?
                                              General
                                   Features
                                              What do you need?
                                References


Easy start




          Python2 (ideally 2.5 since sqlite is bundled with it)
          a text editor
   This is all you need to start developing with Django since Django
   comes with its own lightweight webserver to make it very easy for
   everyone to start playing around with it.




     2
         http://www.python.org
                                                                       13 / 34
What is Django?
                                      General
                           Features
                                      What do you need?
                        References


Yet flexible




                                              SQLite
      FastCGI
                                              MySQL
      mod python
                                              PostgreSQL
      mod wsgi
                                              Oracle in preparation




                                                                      14 / 34
What is Django?    Contributed apps
                               Features   The Template Language
                            References    Simple Form Processing


Main features (for me)



      A good collection of contributed applications
          Administration interface
          Authentication system
          Comments system
          ...
      Template language focused on inheritance
      Simple form processing
      No magic




                                                                   15 / 34
What is Django?    Contributed apps
                            Features   The Template Language
                         References    Simple Form Processing


Administration interface I




                                                                16 / 34
What is Django?    Contributed apps
                               Features   The Template Language
                            References    Simple Form Processing


Administration interface II




       Available in django.contrib.admin
       Configured through model definitions
       Configurable using templates (possible per model),
       JavaScripts and CSS
       Currently a rewrite using newforms is in the pipe.




                                                                   17 / 34
What is Django?    Contributed apps
                                   Features   The Template Language
                                References    Simple Form Processing



Authentication system3




          django.contrib.auth
          Just hook it in, and you get a login screen
          ... and usergroups
          ... and custom permissions




     3
         http://www.djangoproject.com/documentation/authentication/
                                                                       18 / 34
What is Django?    Contributed apps
                                   Features   The Template Language
                                References    Simple Form Processing



django-registration5



          By James Bennett4
          Offers all you really need:
              Simple registration form
              E-mail activation
          Works with django.contrib.auth




     4
         http://www.b-list.org/about/
     5
         http://code.google.com/p/django-registration/
                                                                       19 / 34
What is Django?    Contributed apps
                                 Features   The Template Language
                              References    Simple Form Processing


The Template Language



      Very restrictive
           ... to keep application logic within the View and the Model
           Don’t let templates change the state of your site!
           If you want to have complex code in your templates, you have
           to define your own template tags in Python.
      Inheritance between templates
      You have to pass variables explicitly to the template from the
      view




                                                                          20 / 34
What is Django?    Contributed apps
                                 Features   The Template Language
                              References    Simple Form Processing


Template Basics

     Variables Rendered with
              {{ variable_name }}



        Tags allow you to do more sophisticated stuff while
             keeping the actual Python code out of the template:
              {% template_tag %}



              Even conditional blocks are realized as tags.
       Filters allow you to manipulate the output of a variable:
              {{ variable|filter }}



              E.g.: Escaping strings, converting from Markdown to
              HTML, ...

                                                                     22 / 34
What is Django?    Contributed apps
                                Features   The Template Language
                             References    Simple Form Processing



Template Inheritance6
  The core of inheritance are blocks the templates.
  base.html                            index.html
  <html>                                    {% extends ’base.html’ %}
    <body>                                  {% block title %}
      <h1>                                      Index page
        {% block title %}                   {% endblock %}
        {% endblock %}                      {% block content %}
      </h1>                                     ...
      <div id=quot;contentquot;>                    {% endblock %}
        {% block content %}
        {% endblock %}
      </div>
    </body>
  </html>
     6
       http://www.djangoproject.com/documentation/templates/
   #template-inheritance
                                                                        24 / 34
What is Django?    Contributed apps
                                  Features   The Template Language
                               References    Simple Form Processing



newforms7


         ”newforms” because there was something before that ... let’s
         ignore the only form processing for now ;-)
         Easy way to define forms
         ... to render them
         ... and to validate their data
         Easily combinable with models (as you will see in the
         demoapp)




    7
        http://www.djangoproject.com/documentation/newforms/
                                                                        25 / 34
What is Django?    Contributed apps
                                     Features   The Template Language
                                  References    Simple Form Processing


Form definition



   from d j a n g o import newforms a s f o r m s
   c l a s s CommentForm ( m o d e l s . Form ) :
           a u t h o r = form . C h a r F i e l d ( ’ Your name ’ )
           e m a i l = form . E m a i l F i e l d ( ’ Your e−m a i l )
           body = form . C h a r F i e l d ( ’ Comment ’ ,
                   w i d g e t=f o r m s . T e x t a r e a ( ) )




                                                                         27 / 34
What is Django?          Contributed apps
                                                 Features         The Template Language
                                              References          Simple Form Processing


Form output




   {{ form . a s p }}
  Results in:
  <p> a b e l f o r=” i d a u t h o r ”>Your name :</ l a b e l>
     <l
      <i n p u t i d=” i d a u t h o r ” t y p e=” t e x t ” name=” a u t h o r ” m a x l e n g t h=” 100 ” /></p>
  <p> a b e l f o r=” i d e m a i l ”>Your e−m a i l :</ l a b e l>
     <l
      <i n p u t i d=” i d e m a i l ” t y p e=” t e x t ” name=” e m a i l ” m a x l e n g t h=” 75 ” />  </p>
  <p> a b e l f o r=” i d b o d y ”>Comment :</ l a b e l>
     <l
      <t e x t a r e a i d=” i d b o d y ” rows=” 10 ” c o l s=” 40 ” name=” body ”> t e x t a r e a>
                                                                                               </             </p>




                                                                                                                     29 / 34
What is Django?    Contributed apps
                                      Features   The Template Language
                                   References    Simple Form Processing


Form data validation


   Everything is done in Python, so it’s easily re-usable.
   c l a s s CommentForm ( f o r m s . Form ) :

     # ...

     def c l e a n e m a i l ( s e l f ) :
       e m a i l = s e l f . c l e a n e d d a t a [ ” e m a i l ” ] . s p l i t ( ”@” ) [ 1 ]
       i f e m a i l i n [ ” h o t m a i l . com” , ” yahoo . com” ] :
          r a i s e V a l i d a t i o n E r r o r , ” Get a GMail a c c o u n t ! ”




                                                                                                 31 / 34
What is Django?
                         Features
                      References




“Django project site.” [Online]. Available:
http://www.djangoproject.com/




                                              32 / 34
What is Django?
                                Features
                             References


Thank you




  for your attention.
  Any last question?




                                           33 / 34
What is Django?
                               Features
                            References


Want to get some action?




   If you liked what you saw, we could meet somewhere and build a
   little website together :-)




                                                                    34 / 34

More Related Content

Similar to Introducing Django

Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersRosario Renga
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, DeveloperLinuxmalaysia Malaysia
 
Why Django is The Go-To Framework For Python.pdf
Why Django is The Go-To Framework For Python.pdfWhy Django is The Go-To Framework For Python.pdf
Why Django is The Go-To Framework For Python.pdfMindfire LLC
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| EdurekaEdureka!
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptxsushmitjivtode4
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and ArchitectureAndolasoft Inc
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django frameworkKnoldus Inc.
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in DjangoLakshman Prasad
 
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdf
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdfDjango Tutorial_ Let’s take a deep dive into Django’s web framework.pdf
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdfSudhanshiBakre1
 

Similar to Introducing Django (20)

Django Introdcution
Django IntrodcutionDjango Introdcution
Django Introdcution
 
Django
Django Django
Django
 
Django Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python DevelopersDjango Framework Overview forNon-Python Developers
Django Framework Overview forNon-Python Developers
 
Django
DjangoDjango
Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
* DJANGO - The Python Framework - Low Kian Seong, Developer
    * DJANGO - The Python Framework - Low Kian Seong, Developer    * DJANGO - The Python Framework - Low Kian Seong, Developer
* DJANGO - The Python Framework - Low Kian Seong, Developer
 
Why Django is The Go-To Framework For Python.pdf
Why Django is The Go-To Framework For Python.pdfWhy Django is The Go-To Framework For Python.pdf
Why Django is The Go-To Framework For Python.pdf
 
Django
DjangoDjango
Django
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptx
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Django
DjangoDjango
Django
 
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
Dojango
DojangoDojango
Dojango
 
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdf
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdfDjango Tutorial_ Let’s take a deep dive into Django’s web framework.pdf
Django Tutorial_ Let’s take a deep dive into Django’s web framework.pdf
 

Recently uploaded

Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...ShrutiBose4
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis UsageNeil Kimberley
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024Matteo Carbone
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadAyesha Khan
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...ictsugar
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfrichard876048
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxMarkAnthonyAurellano
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Seta Wicaksana
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 

Recently uploaded (20)

Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
IoT Insurance Observatory: summary 2024
IoT Insurance Observatory:  summary 2024IoT Insurance Observatory:  summary 2024
IoT Insurance Observatory: summary 2024
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Innovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdfInnovation Conference 5th March 2024.pdf
Innovation Conference 5th March 2024.pdf
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
 
Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...Ten Organizational Design Models to align structure and operations to busines...
Ten Organizational Design Models to align structure and operations to busines...
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 

Introducing Django

  • 1. What is Django? Features References Introducing Django Horst Gutmann September 30, 2007 1 / 34
  • 2. What is Django? Features References Disclaimer I’m not of the developers of Django but merely a user who likes what he’s seen. My experience is limited to small sites that can be comfortably run on a shared host such as Dreamhost. And I want to apologize for the noise my laptop is probably going to make during the presentation ;-) 2 / 34
  • 3. What is Django? General Features What do you need? References What is Django? Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. [1] Model-View-Controller for the Web Written in Python Explicit instead of implicit Developed for the Lawrence Journal-World1 newspaper in Kansas 1 http://www2.ljworld.com/ 3 / 34
  • 4. What is Django? General Features What do you need? References What is an MVC web framework? Abstraction 5 / 34
  • 5. What is Django? General Features What do you need? References Abstract HTTP Do we really want to manually parse HTTP requests? Frameworks should automate things like header creation Allow easy cookie handling 6 / 34
  • 6. What is Django? General Features What do you need? References Abstract database calls Page . o b j e c t s . g e t ( i d =10) instead of SELECT ∗ FROM page WHERE i d =10; Not to mention keeping it backend independent and mapping the resultset to objects in the used programming language. 8 / 34
  • 7. What is Django? General Features What do you need? References Dispatch URLs URLs or URL patterns should be mapped to functions or objects ... that then create the output. u r l p a t t e r n s += p a t t e r n s ( ’ ’ , u r l ( ’ ˆ$ ’ , ’ v i e w s . i n d e x ’ ) , ) 10 / 34
  • 8. What is Django? General Features What do you need? References MVC or MVT? Django uses a little bit different naming for the Model-View-Controller pattern. Models abstract the used data by defining classes for them and storing them in relational tables. Views take the job of the controllers in MVC and basically define, what the user gets to see. Functions, not classes here. Templates define how the users see the view 11 / 34
  • 9. What is Django? General Features What do you need? References Projects and Applications Project A project is for example your whole website. Here you store your central configuration and general templates and images (just as an example). Applications are where you store the actual functionality. For example a weblog would be an application. An account system would be an application ... Applications are a simple way to share common functionality between various projects. 12 / 34
  • 10. What is Django? General Features What do you need? References Easy start Python2 (ideally 2.5 since sqlite is bundled with it) a text editor This is all you need to start developing with Django since Django comes with its own lightweight webserver to make it very easy for everyone to start playing around with it. 2 http://www.python.org 13 / 34
  • 11. What is Django? General Features What do you need? References Yet flexible SQLite FastCGI MySQL mod python PostgreSQL mod wsgi Oracle in preparation 14 / 34
  • 12. What is Django? Contributed apps Features The Template Language References Simple Form Processing Main features (for me) A good collection of contributed applications Administration interface Authentication system Comments system ... Template language focused on inheritance Simple form processing No magic 15 / 34
  • 13. What is Django? Contributed apps Features The Template Language References Simple Form Processing Administration interface I 16 / 34
  • 14. What is Django? Contributed apps Features The Template Language References Simple Form Processing Administration interface II Available in django.contrib.admin Configured through model definitions Configurable using templates (possible per model), JavaScripts and CSS Currently a rewrite using newforms is in the pipe. 17 / 34
  • 15. What is Django? Contributed apps Features The Template Language References Simple Form Processing Authentication system3 django.contrib.auth Just hook it in, and you get a login screen ... and usergroups ... and custom permissions 3 http://www.djangoproject.com/documentation/authentication/ 18 / 34
  • 16. What is Django? Contributed apps Features The Template Language References Simple Form Processing django-registration5 By James Bennett4 Offers all you really need: Simple registration form E-mail activation Works with django.contrib.auth 4 http://www.b-list.org/about/ 5 http://code.google.com/p/django-registration/ 19 / 34
  • 17. What is Django? Contributed apps Features The Template Language References Simple Form Processing The Template Language Very restrictive ... to keep application logic within the View and the Model Don’t let templates change the state of your site! If you want to have complex code in your templates, you have to define your own template tags in Python. Inheritance between templates You have to pass variables explicitly to the template from the view 20 / 34
  • 18. What is Django? Contributed apps Features The Template Language References Simple Form Processing Template Basics Variables Rendered with {{ variable_name }} Tags allow you to do more sophisticated stuff while keeping the actual Python code out of the template: {% template_tag %} Even conditional blocks are realized as tags. Filters allow you to manipulate the output of a variable: {{ variable|filter }} E.g.: Escaping strings, converting from Markdown to HTML, ... 22 / 34
  • 19. What is Django? Contributed apps Features The Template Language References Simple Form Processing Template Inheritance6 The core of inheritance are blocks the templates. base.html index.html <html> {% extends ’base.html’ %} <body> {% block title %} <h1> Index page {% block title %} {% endblock %} {% endblock %} {% block content %} </h1> ... <div id=quot;contentquot;> {% endblock %} {% block content %} {% endblock %} </div> </body> </html> 6 http://www.djangoproject.com/documentation/templates/ #template-inheritance 24 / 34
  • 20. What is Django? Contributed apps Features The Template Language References Simple Form Processing newforms7 ”newforms” because there was something before that ... let’s ignore the only form processing for now ;-) Easy way to define forms ... to render them ... and to validate their data Easily combinable with models (as you will see in the demoapp) 7 http://www.djangoproject.com/documentation/newforms/ 25 / 34
  • 21. What is Django? Contributed apps Features The Template Language References Simple Form Processing Form definition from d j a n g o import newforms a s f o r m s c l a s s CommentForm ( m o d e l s . Form ) : a u t h o r = form . C h a r F i e l d ( ’ Your name ’ ) e m a i l = form . E m a i l F i e l d ( ’ Your e−m a i l ) body = form . C h a r F i e l d ( ’ Comment ’ , w i d g e t=f o r m s . T e x t a r e a ( ) ) 27 / 34
  • 22. What is Django? Contributed apps Features The Template Language References Simple Form Processing Form output {{ form . a s p }} Results in: <p> a b e l f o r=” i d a u t h o r ”>Your name :</ l a b e l> <l <i n p u t i d=” i d a u t h o r ” t y p e=” t e x t ” name=” a u t h o r ” m a x l e n g t h=” 100 ” /></p> <p> a b e l f o r=” i d e m a i l ”>Your e−m a i l :</ l a b e l> <l <i n p u t i d=” i d e m a i l ” t y p e=” t e x t ” name=” e m a i l ” m a x l e n g t h=” 75 ” /> </p> <p> a b e l f o r=” i d b o d y ”>Comment :</ l a b e l> <l <t e x t a r e a i d=” i d b o d y ” rows=” 10 ” c o l s=” 40 ” name=” body ”> t e x t a r e a> </ </p> 29 / 34
  • 23. What is Django? Contributed apps Features The Template Language References Simple Form Processing Form data validation Everything is done in Python, so it’s easily re-usable. c l a s s CommentForm ( f o r m s . Form ) : # ... def c l e a n e m a i l ( s e l f ) : e m a i l = s e l f . c l e a n e d d a t a [ ” e m a i l ” ] . s p l i t ( ”@” ) [ 1 ] i f e m a i l i n [ ” h o t m a i l . com” , ” yahoo . com” ] : r a i s e V a l i d a t i o n E r r o r , ” Get a GMail a c c o u n t ! ” 31 / 34
  • 24. What is Django? Features References “Django project site.” [Online]. Available: http://www.djangoproject.com/ 32 / 34
  • 25. What is Django? Features References Thank you for your attention. Any last question? 33 / 34
  • 26. What is Django? Features References Want to get some action? If you liked what you saw, we could meet somewhere and build a little website together :-) 34 / 34