SlideShare a Scribd company logo
Introduction to Django
    Master en Software Libre Caixanova

              May 22nd 2009
whoami


●   Portuguese since 1985
●   GTK+ developer
●   Proud Pythonista
●   Djangonaut since 2007
●   Igalian since 2008
And if you insist... http://www.joaquimrocha.com



                       MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
My Latest Django Project




               Rancho
http://www.getrancho.com




   MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
What's Django




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
What's Django?



quot;Django is a high-level Python Web framework
that encourages rapid development and clean,
pragmatic design.quot;
From Django official website




                               MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Young But Strong



●   Internal project of Lawrence Journal-World in
    2003
●   Should help journalists meet fast deadlines
●   Should not stand in the journalists' way
●   Got its name after the famous guitarrist Django
    Reinhardt


                 MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
The Framework


●   Object-Relational Mapper
●   Automatic Admin Interface
●   Elegant URL Design
●   Powerful Template System
●   i18n
it's amazing...!



                   MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
MTV




Model-Template-View

●   Model: What things are
●   Templates: How things are presented
●   Views: How things are processed


                MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Deployment



●   FastCGI
●   mod_python
●   mod_wsgi
●   ...



                 MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
DB Backend



●   PostgreSQL
●   MySQL
●   SQLite
●   Oracle



                 MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Big Community



●   Django People:
     –    http://djangopeople.net
●   Django Pluggables:
     –    http://djangopluggables.com
●   Django Sites:
     –    http://www.djangosites.org
●   ...


                          MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Using Django




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Installation


Just get a tarball release or checkout the sources:
   http://www.djangoproject.com/download/


Then:
   # python setup.py install


... yeah, that it!

                       MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Development




Django Projects have applications




        MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Project



$ django-admin.py startproject Project

               Project/
                 __init__.py
                 manage.py
                 settings.py
                 urls.py


       MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Project


Does it work?


                $ ./manage.py runserver




                MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Project




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Applications

Apps are the project's components

          $ ./manage.py startapp recipe

  recipe/
     __init__.py
     models.py
     tests.py
     views.py


             MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Configuration




        settings.py
      Easy configuration




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Building The Database




$ ./manage.py syncdb



  MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Models

models.py, series of classes describing objects




Represent the database objects.
Never touch SQL again!




                            MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Models



class Post(models.Model):
   title = models.CharField(max_length = 500)
   content = models.TextField()
   date = models.DateTimeField(auto_now = True)
    ...




                 MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Views

views.py, series of functions that will normally process some models and render HTML




                           Where the magic happen!



        How to get all blog posts from the latest 5 days and order them by
                                      descending date?



                           MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Views

import datetime


def view_latest_posts(request):
    # Last 5 days
    date = datetime.datetime.now() -
                       datetime.timedelta(5)
    posts = Post.objects.filter(date__gte =
                                date).order_by('-date')

   return render_to_response('posts/show_posts.html',
                             {'posts': posts})



                  MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Template




 Will let you not repeat yourself!

Will save designers from the code.




       MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Template


<html>
  <head>
    <title>{% block title %}{% endblock %}</title>
  </head>
  <body>
    {% block content %}{% endblock %}
  </body>
</html>




              MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Template

{% extends quot;base.htmlquot; %}

{% block title %}Homepage{% endblock %}

{% block content %}
  <h3>This will be some main content</h3>

 {% for post in posts %}
   <h4>{{ post.title }} on {{ post.date|date:quot;B d, Yquot;|upper }}<h4>

   <p>{{ post.content }}</p>
 {% endfor %}

 {% url project.some_app.views.some_view some arguments %}

{% endblock %}



                     MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
URLs




In Django, URLs are part of the
            design!



       MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
URLs

urls.py use regular expressions to match URLs with views


urlpatterns = patterns('Project.some_app.views',
    (r'^$', 'index'),

    (r'^posts/(?P<r_id>d+)/$', 'view_latest_posts'),

    (r'^create/$', 'create'),
)




                           MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Forms

forms.py, series of classes that represent an HTML form




Will let you easily configure the expected type of the
inputs, error messages, labels, etc...




                           MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Forms


class CreatePost(forms.Form):
  title = forms.CharField(label = quot;Post Titlequot;,
                           max_length = 500,
              widget = forms.TextInput(attrs={
                             'class': 'big_entry'
                              }))
  content = forms.CharField()
  tags = forms.CharField(required = False)




                MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Forms

def create_post(request):
  if request.method == 'POST':
    form = CreatePost(request.POST)
    if form.is_valid():
        # Create a new post object with data
        # from form.cleaned_data
        return HttpResponseRedirect('/index/')
  else:
    form = CreatePost()

return render_to_response('create.html', {
                           'form': form,
                           })

                 MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Forms


The quick way...


<form action=quot;/create/quot; method=quot;POSTquot;>
  {{ form.as_p }}
  <input type=quot;submitquot; value=quot;Createquot; />
</form>



                   MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Performance




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
Performance




For those who doubt...

http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-
frameworks/




                         MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
HELP!




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
HELP!

Django Docs

           http://docs.djangoproject.com

Some books

●   Learning Website Development with Django,
    Packt
●   Practical Django Projects, Apress
●   Pro Django, Apress
                MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
End




  Thank you!
       Questions?




MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com

More Related Content

Similar to Django Intro

Pwa, separating the features from the solutions
Pwa, separating the features from the solutions Pwa, separating the features from the solutions
Pwa, separating the features from the solutions
Sander Mangel
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
Udi Bauman
 
BackboneJS and friends
BackboneJS and friendsBackboneJS and friends
BackboneJS and friendsScott Cowan
 
Schoology vs baabtra
Schoology vs baabtraSchoology vs baabtra
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワークTakatsugu Shigeta
 
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
Igor Sobreira
 
Week 8
Week 8Week 8
Week 8
A VD
 
A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019
Matt Raible
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
Mohd Manzoor Ahmed
 
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Cyrille Le Clerc
 
Bubbles and Trees with jQuery
Bubbles and Trees with jQueryBubbles and Trees with jQuery
Bubbles and Trees with jQuery
westhoff
 
Developing jQuery Plugins with Ease
Developing jQuery Plugins with EaseDeveloping jQuery Plugins with Ease
Developing jQuery Plugins with Ease
westhoff
 
Developing Sakai 3 style tools in Sakai 2.x
Developing Sakai 3 style tools in Sakai 2.xDeveloping Sakai 3 style tools in Sakai 2.x
Developing Sakai 3 style tools in Sakai 2.x
AuSakai
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace
 
User story slicing exercise
User story slicing exerciseUser story slicing exercise
User story slicing exercise
Paulo Clavijo
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Presentasi seminar it amikom
Presentasi seminar it amikomPresentasi seminar it amikom
Presentasi seminar it amikom
Melwin Syafrizal
 
Magento Presentation Layer
Magento Presentation LayerMagento Presentation Layer
Magento Presentation Layer
Volodymyr Kublytskyi
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Pablo Godel
 

Similar to Django Intro (19)

Pwa, separating the features from the solutions
Pwa, separating the features from the solutions Pwa, separating the features from the solutions
Pwa, separating the features from the solutions
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
BackboneJS and friends
BackboneJS and friendsBackboneJS and friends
BackboneJS and friends
 
Schoology vs baabtra
Schoology vs baabtraSchoology vs baabtra
Schoology vs baabtra
 
シックス・アパート・フレームワーク
シックス・アパート・フレームワークシックス・アパート・フレームワーク
シックス・アパート・フレームワーク
 
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
 
Week 8
Week 8Week 8
Week 8
 
A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Angular SF 2019
 
3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC3-TIER ARCHITECTURE IN ASP.NET MVC
3-TIER ARCHITECTURE IN ASP.NET MVC
 
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
Open Source Monitoring for Java with JMX and Graphite (GeeCON 2013)
 
Bubbles and Trees with jQuery
Bubbles and Trees with jQueryBubbles and Trees with jQuery
Bubbles and Trees with jQuery
 
Developing jQuery Plugins with Ease
Developing jQuery Plugins with EaseDeveloping jQuery Plugins with Ease
Developing jQuery Plugins with Ease
 
Developing Sakai 3 style tools in Sakai 2.x
Developing Sakai 3 style tools in Sakai 2.xDeveloping Sakai 3 style tools in Sakai 2.x
Developing Sakai 3 style tools in Sakai 2.x
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
User story slicing exercise
User story slicing exerciseUser story slicing exercise
User story slicing exercise
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Presentasi seminar it amikom
Presentasi seminar it amikomPresentasi seminar it amikom
Presentasi seminar it amikom
 
Magento Presentation Layer
Magento Presentation LayerMagento Presentation Layer
Magento Presentation Layer
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 

Recently uploaded

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 

Recently uploaded (20)

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 

Django Intro

  • 1. Introduction to Django Master en Software Libre Caixanova May 22nd 2009
  • 2. whoami ● Portuguese since 1985 ● GTK+ developer ● Proud Pythonista ● Djangonaut since 2007 ● Igalian since 2008 And if you insist... http://www.joaquimrocha.com MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 3. My Latest Django Project Rancho http://www.getrancho.com MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 4. What's Django MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 5. What's Django? quot;Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.quot; From Django official website MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 6. Young But Strong ● Internal project of Lawrence Journal-World in 2003 ● Should help journalists meet fast deadlines ● Should not stand in the journalists' way ● Got its name after the famous guitarrist Django Reinhardt MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 7. The Framework ● Object-Relational Mapper ● Automatic Admin Interface ● Elegant URL Design ● Powerful Template System ● i18n it's amazing...! MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 8. MTV Model-Template-View ● Model: What things are ● Templates: How things are presented ● Views: How things are processed MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 9. Deployment ● FastCGI ● mod_python ● mod_wsgi ● ... MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 10. DB Backend ● PostgreSQL ● MySQL ● SQLite ● Oracle MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 11. Big Community ● Django People: – http://djangopeople.net ● Django Pluggables: – http://djangopluggables.com ● Django Sites: – http://www.djangosites.org ● ... MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 12. Using Django MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 13. Installation Just get a tarball release or checkout the sources: http://www.djangoproject.com/download/ Then: # python setup.py install ... yeah, that it! MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 14. Development Django Projects have applications MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 15. Project $ django-admin.py startproject Project Project/ __init__.py manage.py settings.py urls.py MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 16. Project Does it work? $ ./manage.py runserver MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 17. Project MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 18. Applications Apps are the project's components $ ./manage.py startapp recipe recipe/ __init__.py models.py tests.py views.py MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 19. Configuration settings.py Easy configuration MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 20. Building The Database $ ./manage.py syncdb MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 21. Models models.py, series of classes describing objects Represent the database objects. Never touch SQL again! MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 22. Models class Post(models.Model): title = models.CharField(max_length = 500) content = models.TextField() date = models.DateTimeField(auto_now = True) ... MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 23. Views views.py, series of functions that will normally process some models and render HTML Where the magic happen! How to get all blog posts from the latest 5 days and order them by descending date? MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 24. Views import datetime def view_latest_posts(request): # Last 5 days date = datetime.datetime.now() - datetime.timedelta(5) posts = Post.objects.filter(date__gte = date).order_by('-date') return render_to_response('posts/show_posts.html', {'posts': posts}) MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 25. Template Will let you not repeat yourself! Will save designers from the code. MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 26. Template <html> <head> <title>{% block title %}{% endblock %}</title> </head> <body> {% block content %}{% endblock %} </body> </html> MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 27. Template {% extends quot;base.htmlquot; %} {% block title %}Homepage{% endblock %} {% block content %} <h3>This will be some main content</h3> {% for post in posts %} <h4>{{ post.title }} on {{ post.date|date:quot;B d, Yquot;|upper }}<h4> <p>{{ post.content }}</p> {% endfor %} {% url project.some_app.views.some_view some arguments %} {% endblock %} MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 28. URLs In Django, URLs are part of the design! MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 29. URLs urls.py use regular expressions to match URLs with views urlpatterns = patterns('Project.some_app.views', (r'^$', 'index'), (r'^posts/(?P<r_id>d+)/$', 'view_latest_posts'), (r'^create/$', 'create'), ) MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 30. Forms forms.py, series of classes that represent an HTML form Will let you easily configure the expected type of the inputs, error messages, labels, etc... MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 31. Forms class CreatePost(forms.Form): title = forms.CharField(label = quot;Post Titlequot;, max_length = 500, widget = forms.TextInput(attrs={ 'class': 'big_entry' })) content = forms.CharField() tags = forms.CharField(required = False) MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 32. Forms def create_post(request): if request.method == 'POST': form = CreatePost(request.POST) if form.is_valid(): # Create a new post object with data # from form.cleaned_data return HttpResponseRedirect('/index/') else: form = CreatePost() return render_to_response('create.html', { 'form': form, }) MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 33. Forms The quick way... <form action=quot;/create/quot; method=quot;POSTquot;> {{ form.as_p }} <input type=quot;submitquot; value=quot;Createquot; /> </form> MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 34. Performance MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 35. Performance For those who doubt... http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading- frameworks/ MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 36. MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 37. HELP! MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 38. HELP! Django Docs http://docs.djangoproject.com Some books ● Learning Website Development with Django, Packt ● Practical Django Projects, Apress ● Pro Django, Apress MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com
  • 39. End Thank you! Questions? MSWL Caixanova · Vigo · May 22nd 2009 | Joaquim Rocha | jrocha@igalia.com