SlideShare a Scribd company logo
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 Introdcution
Django IntrodcutionDjango Introdcution
Django Introdcution
Nagi Annapureddy
 
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
Rosario Renga
 
Django
DjangoDjango
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Ahmed 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, Developer
Linuxmalaysia 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.pdf
Mindfire LLC
 
Django
DjangoDjango
Django
Harjot Mann
 
Django Framework Interview Guide - Part 1
Django Framework Interview Guide - Part 1Django Framework Interview Guide - Part 1
Django Framework Interview Guide - Part 1
To Sum It Up
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
Edureka!
 
Django by rj
Django by rjDjango 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
fantabulous2024
 
Django PPT.pptx
Django PPT.pptxDjango PPT.pptx
Django PPT.pptx
KhyatiBandi1
 
Concepts and applications of Django.pptx
Concepts and applications of Django.pptxConcepts and applications of Django.pptx
Concepts and applications of Django.pptx
sushmitjivtode4
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
Andolasoft Inc
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
Knoldus Inc.
 
Django
DjangoDjango
Web Development in Django
Web Development in DjangoWeb Development in Django
Web Development in Django
Lakshman Prasad
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
Kaleem Ullah Mangrio
 
Dojango
DojangoDojango
Dojango
klipstein
 

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 Framework Interview Guide - Part 1
Django Framework Interview Guide - Part 1Django Framework Interview Guide - Part 1
Django Framework Interview Guide - Part 1
 
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
 

Recently uploaded

The latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from NewentideThe latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from Newentide
JoeYangGreatMachiner
 
2022 Vintage Roman Numerals Men Rings
2022 Vintage Roman  Numerals  Men  Rings2022 Vintage Roman  Numerals  Men  Rings
2022 Vintage Roman Numerals Men Rings
aragme
 
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel ChartSatta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
taqyea
 
Best practices for project execution and delivery
Best practices for project execution and deliveryBest practices for project execution and delivery
Best practices for project execution and delivery
CLIVE MINCHIN
 
Cover Story - China's Investment Leader - Dr. Alyce SU
Cover Story - China's Investment Leader - Dr. Alyce SUCover Story - China's Investment Leader - Dr. Alyce SU
Cover Story - China's Investment Leader - Dr. Alyce SU
msthrill
 
list of states and organizations .pdf
list of  states  and  organizations .pdflist of  states  and  organizations .pdf
list of states and organizations .pdf
Rbc Rbcua
 
Part 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 SlowdownPart 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 Slowdown
jeffkluth1
 
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
taqyea
 
The Genesis of BriansClub.cm Famous Dark WEb Platform
The Genesis of BriansClub.cm Famous Dark WEb PlatformThe Genesis of BriansClub.cm Famous Dark WEb Platform
The Genesis of BriansClub.cm Famous Dark WEb Platform
SabaaSudozai
 
The Most Inspiring Entrepreneurs to Follow in 2024.pdf
The Most Inspiring Entrepreneurs to Follow in 2024.pdfThe Most Inspiring Entrepreneurs to Follow in 2024.pdf
The Most Inspiring Entrepreneurs to Follow in 2024.pdf
thesiliconleaders
 
Digital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on SustainabilityDigital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on Sustainability
sssourabhsharma
 
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Stone Art Hub
 
The Steadfast and Reliable Bull: Taurus Zodiac Sign
The Steadfast and Reliable Bull: Taurus Zodiac SignThe Steadfast and Reliable Bull: Taurus Zodiac Sign
The Steadfast and Reliable Bull: Taurus Zodiac Sign
my Pandit
 
Pitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deckPitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deck
HajeJanKamps
 
Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024
Adnet Communications
 
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdfGarments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
Pridesys IT Ltd.
 
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
Herman Kienhuis
 
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdfRegistered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
dazzjoker
 

Recently uploaded (20)

The latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from NewentideThe latest Heat Pump Manual from Newentide
The latest Heat Pump Manual from Newentide
 
2022 Vintage Roman Numerals Men Rings
2022 Vintage Roman  Numerals  Men  Rings2022 Vintage Roman  Numerals  Men  Rings
2022 Vintage Roman Numerals Men Rings
 
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel ChartSatta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
Satta Matka Dpboss Matka Guessing Kalyan Chart Indian Matka Kalyan panel Chart
 
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
一比一原版新西兰奥塔哥大学毕业证(otago毕业证)如何办理
 
Best practices for project execution and delivery
Best practices for project execution and deliveryBest practices for project execution and delivery
Best practices for project execution and delivery
 
Cover Story - China's Investment Leader - Dr. Alyce SU
Cover Story - China's Investment Leader - Dr. Alyce SUCover Story - China's Investment Leader - Dr. Alyce SU
Cover Story - China's Investment Leader - Dr. Alyce SU
 
list of states and organizations .pdf
list of  states  and  organizations .pdflist of  states  and  organizations .pdf
list of states and organizations .pdf
 
Part 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 SlowdownPart 2 Deep Dive: Navigating the 2024 Slowdown
Part 2 Deep Dive: Navigating the 2024 Slowdown
 
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
一比一原版(QMUE毕业证书)英国爱丁堡玛格丽特女王大学毕业证文凭如何办理
 
The Genesis of BriansClub.cm Famous Dark WEb Platform
The Genesis of BriansClub.cm Famous Dark WEb PlatformThe Genesis of BriansClub.cm Famous Dark WEb Platform
The Genesis of BriansClub.cm Famous Dark WEb Platform
 
The Most Inspiring Entrepreneurs to Follow in 2024.pdf
The Most Inspiring Entrepreneurs to Follow in 2024.pdfThe Most Inspiring Entrepreneurs to Follow in 2024.pdf
The Most Inspiring Entrepreneurs to Follow in 2024.pdf
 
Digital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on SustainabilityDigital Marketing with a Focus on Sustainability
Digital Marketing with a Focus on Sustainability
 
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666Best Competitive Marble Pricing in Dubai - ☎ 9928909666
Best Competitive Marble Pricing in Dubai - ☎ 9928909666
 
The Steadfast and Reliable Bull: Taurus Zodiac Sign
The Steadfast and Reliable Bull: Taurus Zodiac SignThe Steadfast and Reliable Bull: Taurus Zodiac Sign
The Steadfast and Reliable Bull: Taurus Zodiac Sign
 
Pitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deckPitch Deck Teardown: Kinnect's $250k Angel deck
Pitch Deck Teardown: Kinnect's $250k Angel deck
 
Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024
 
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdfGarments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
Garments ERP Software in Bangladesh _ Pridesys IT Ltd.pdf
 
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
Presentation by Herman Kienhuis (Curiosity VC) on Investing in AI for ABS Alu...
 
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
Dpboss Matka Guessing Satta Matta Matka Kalyan panel Chart Indian Matka Dpbos...
 
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdfRegistered-Establishment-List-in-Uttarakhand-pdf.pdf
Registered-Establishment-List-in-Uttarakhand-pdf.pdf
 

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