SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Django introduction

   Kevin Van Wilder
      www.inuits.eu
Topics
• What is Django?
• Framework overview
• Getting started
Who uses Django?
•   Pinterest           •   New York Times
•   Instagram           •   Washington Post
•   Openstack           •   The Guardian
•   Disqus              •   Mercedes Benz
•   Firefox             •   National Geographic
•   NASA                •   Discovery Channel
•   Bitbucket           •   Orange
•   The Onion           •   ...
What is Django?
• Not a CMS!
• Web application framework to create
  complex, dynamic and datadriven websites
  with emphasis on:
  – Loose coupling and tight cohesion
  – Less code
  – Quick development
  – DRY
  – Consistent
Features
• Admin interface (CRUD)
• Templating
• Form handling
• Internationalisation (i18n)
• Sessions, User management, role-based
  permissions.
• Object-Relational Mapping (ORM)
• Testing Framework
• Fantastic documentation
FRAMEWORK OVERVIEW
Models


 Views


Templates



                   Application
 Models


 Views


Templates
                   Application
                                 Site/Project
                                                Project Structure




      Settings


            Urls


     Templates
Model, View, Template
• Model
  – Abstracts data by defining classes for them and
    stores them in relational tables
• View
  – Takes a browser request and generates what the
    user gets to see
• Template
  – Defines how the user will see the view
Framework
URLConf
• URLs are matched via patterns and mapped
  View functions/classes that create the output.

    urlpatterns = patterns('',
        url(r'^$',
            TipListView.as_view(),
            name='tip-list'),


        url(r'^tips/(?P<slug>[-w]+)/$',
            TipDetailView.as_view(),
            name='tip-detail'),
    )
Views
• Receives a request and generates a response
• Interacts with:
   – Models
   – Templates
   – Caching
• Mostly fits inside one of the following categories:
   –   Show a list of objects
   –   Show details of an object
   –   Create/Update/Delete an object
   –   Show objects by year, month, week, day...
Views (continued)
• Just rendering text:
  – TemplateView
• If that doesn’t float your boat: Mixins
  – SingleObjectMixin
  – FormMixin
  – ModelFormMixin
  – ...
Overview

urlpatterns = patterns('',

    url(r'^books/([w-]+)/$',
        PublisherBookList.as_view(),
        name='author-detail'),

)


class PublisherBookList(ListView):

    template_name = 'books/books_by_publisher.html'

    def get_queryset(self):
        self.publisher = get_object_or_404(Publisher, name=self.args[0])
        return Book.objects.filter(publisher=self.publisher)
Templates
{% extends "base_generic.html" %}

{% block title %}
    {{ publisher.name }}
{% endblock %}

{% block content %}
    <h1>{{ publisher.name }}</h1>
    {% for book in object_list %}
        <h2>
             <a href="{{ book.get_absolute_url }}">
                 {{ book.title }}
             </a>
        </h2>
    {% endfor %}
{% endblock %}
Models
• Abstract representation of data
• Database independent
• Object oriented (methods, inheritance, etc)
from django.db import models

class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

   class Meta:
       ordering = ["-name"]

   def __unicode__(self):
       return self.name


class Book(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField('Author')
    publisher = models.ForeignKey(Publisher)
    publication_date = models.DateField()
Querying the ORM


Book.objects.get(title=“On the Origin of Species”)



SELECT *
FROM books
WHERE title = “On the Origin of species”;
Querying the ORM
Books.objects

  .filter(genre=“drama”)
  .order_by(“-publish_date”)
  .annotate(author_count=Count(‘author’))
  .only(“title”, “publish_date”, “genre”)
GETTING STARTED
Working on “Onderwijstips”
# SETTING UP ENVIRONMENT
$ mkvirtualenv onderwijstips

#   CHECKING OUT THE CODE
$   git clone git@github.ugent.be:Portaal/site-onderwijstips.git
$   cd site-onderwijstips
$   git checkout develop

#   BUILDING
$   ln –s buildout_dev.cfg buildout.cfg
$   python bootstrap.py
$   bin/buildout –vv # uses private github projects, requires permissions

# STARTING DJANGO
$ bin/django migrate
$ bin/django runserver
Git Repository
• Git Flow (http://nvie.com/posts/a-successful-git-branching-model/)
   – master
       • Always tagged with a version
       • To be deployed
   – develop
       • Next version currently in development
   – release/1.x.x
       • A release being prepared
       • Merges into master with tag 1.x.x
How are we deploying?
• Configuration:
  – Apache2 + mod_wsgi
  – MySQL
  – Optimize only when necessary
    (varnish, memcache, ...)
• Jenkins pipeline
  –   Perform a buildout
  –   Generate .deb file
  –   Upload to Infrastructure Package Repository
  –   Triggers a Puppet run
Onderwijstips
• Three applications
   – Tips (front-end for users)
   – Editors (back-end for tip author)
   – Migration (plomino importer)
• Features:
   –   Haystack search indexing (django-haystack)
   –   User authentication (django-cas)
   –   MediaMosa Integration (django-mediamosa)
   –   Tagging (django-taggit)
   –   Ugent Theming (django-ugent)
• Buildout (Thx Bert!)
• Monitoring via Sentry
• Database schema migration management via South
DEMO TIME!

Contenu connexe

Tendances

9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North DelhiJessica Smith
 
6 Months PHP internship in Noida
6 Months PHP internship in Noida6 Months PHP internship in Noida
6 Months PHP internship in NoidaTech Mentro
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentCindy Royal
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery LearningUzair Ali
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)jeresig
 
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryToni Kolev
 
Introuction To jQuery
Introuction To jQueryIntrouction To jQuery
Introuction To jQueryWinster Lee
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)Mike Dirolf
 
W3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayW3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayadeveria
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1Toni Kolev
 
An introduction to jQuery
An introduction to jQueryAn introduction to jQuery
An introduction to jQueryJames Wragg
 
Sakai customization talk
Sakai customization talkSakai customization talk
Sakai customization talkcroby
 
Hands-on Guide to Object Identification
Hands-on Guide to Object IdentificationHands-on Guide to Object Identification
Hands-on Guide to Object IdentificationDharmesh Vaya
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)jeresig
 
Why I liked Mezzanine CMS
Why I liked Mezzanine CMSWhy I liked Mezzanine CMS
Why I liked Mezzanine CMSRenyi Khor
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)jeresig
 

Tendances (19)

9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi9 Months Web Development Diploma Course in North Delhi
9 Months Web Development Diploma Course in North Delhi
 
6 Months PHP internship in Noida
6 Months PHP internship in Noida6 Months PHP internship in Noida
6 Months PHP internship in Noida
 
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
 
PhDigital 2020: Web Development
PhDigital 2020: Web DevelopmentPhDigital 2020: Web Development
PhDigital 2020: Web Development
 
Jquery
JqueryJquery
Jquery
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)
 
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQueryFFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - jQuery
 
Introuction To jQuery
Introuction To jQueryIntrouction To jQuery
Introuction To jQuery
 
MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)MongoDB hearts Django? (Django NYC)
MongoDB hearts Django? (Django NYC)
 
W3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use todayW3Conf slides - The top web features from caniuse.com you can use today
W3Conf slides - The top web features from caniuse.com you can use today
 
FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1FFW Gabrovo PMG - JavaScript 1
FFW Gabrovo PMG - JavaScript 1
 
An introduction to jQuery
An introduction to jQueryAn introduction to jQuery
An introduction to jQuery
 
Sakai customization talk
Sakai customization talkSakai customization talk
Sakai customization talk
 
Hands-on Guide to Object Identification
Hands-on Guide to Object IdentificationHands-on Guide to Object Identification
Hands-on Guide to Object Identification
 
JQuery
JQueryJQuery
JQuery
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
 
Why I liked Mezzanine CMS
Why I liked Mezzanine CMSWhy I liked Mezzanine CMS
Why I liked Mezzanine CMS
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
 

Similaire à Django Introduction: A Guide to the Popular Python Web Framework

Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTTkevinvw
 
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointMarc D Anderson
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsMark Rackley
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Djangoryates
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Lucidworks
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Mark Hamstra
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle Mark Hamstra
 

Similaire à Django Introduction: A Guide to the Popular Python Web Framework (20)

Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePoint
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
 
Jumpstart Django
Jumpstart DjangoJumpstart Django
Jumpstart Django
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 

Dernier

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Dernier (20)

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Django Introduction: A Guide to the Popular Python Web Framework

  • 1. Django introduction Kevin Van Wilder www.inuits.eu
  • 2. Topics • What is Django? • Framework overview • Getting started
  • 3. Who uses Django? • Pinterest • New York Times • Instagram • Washington Post • Openstack • The Guardian • Disqus • Mercedes Benz • Firefox • National Geographic • NASA • Discovery Channel • Bitbucket • Orange • The Onion • ...
  • 4. What is Django? • Not a CMS! • Web application framework to create complex, dynamic and datadriven websites with emphasis on: – Loose coupling and tight cohesion – Less code – Quick development – DRY – Consistent
  • 5. Features • Admin interface (CRUD) • Templating • Form handling • Internationalisation (i18n) • Sessions, User management, role-based permissions. • Object-Relational Mapping (ORM) • Testing Framework • Fantastic documentation
  • 7. Models Views Templates Application Models Views Templates Application Site/Project Project Structure Settings Urls Templates
  • 8. Model, View, Template • Model – Abstracts data by defining classes for them and stores them in relational tables • View – Takes a browser request and generates what the user gets to see • Template – Defines how the user will see the view
  • 10. URLConf • URLs are matched via patterns and mapped View functions/classes that create the output. urlpatterns = patterns('', url(r'^$', TipListView.as_view(), name='tip-list'), url(r'^tips/(?P<slug>[-w]+)/$', TipDetailView.as_view(), name='tip-detail'), )
  • 11. Views • Receives a request and generates a response • Interacts with: – Models – Templates – Caching • Mostly fits inside one of the following categories: – Show a list of objects – Show details of an object – Create/Update/Delete an object – Show objects by year, month, week, day...
  • 12. Views (continued) • Just rendering text: – TemplateView • If that doesn’t float your boat: Mixins – SingleObjectMixin – FormMixin – ModelFormMixin – ...
  • 13. Overview urlpatterns = patterns('', url(r'^books/([w-]+)/$', PublisherBookList.as_view(), name='author-detail'), ) class PublisherBookList(ListView): template_name = 'books/books_by_publisher.html' def get_queryset(self): self.publisher = get_object_or_404(Publisher, name=self.args[0]) return Book.objects.filter(publisher=self.publisher)
  • 14. Templates {% extends "base_generic.html" %} {% block title %} {{ publisher.name }} {% endblock %} {% block content %} <h1>{{ publisher.name }}</h1> {% for book in object_list %} <h2> <a href="{{ book.get_absolute_url }}"> {{ book.title }} </a> </h2> {% endfor %} {% endblock %}
  • 15. Models • Abstract representation of data • Database independent • Object oriented (methods, inheritance, etc)
  • 16. from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_length=50) city = models.CharField(max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() class Meta: ordering = ["-name"] def __unicode__(self): return self.name class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField('Author') publisher = models.ForeignKey(Publisher) publication_date = models.DateField()
  • 17. Querying the ORM Book.objects.get(title=“On the Origin of Species”) SELECT * FROM books WHERE title = “On the Origin of species”;
  • 18. Querying the ORM Books.objects .filter(genre=“drama”) .order_by(“-publish_date”) .annotate(author_count=Count(‘author’)) .only(“title”, “publish_date”, “genre”)
  • 20. Working on “Onderwijstips” # SETTING UP ENVIRONMENT $ mkvirtualenv onderwijstips # CHECKING OUT THE CODE $ git clone git@github.ugent.be:Portaal/site-onderwijstips.git $ cd site-onderwijstips $ git checkout develop # BUILDING $ ln –s buildout_dev.cfg buildout.cfg $ python bootstrap.py $ bin/buildout –vv # uses private github projects, requires permissions # STARTING DJANGO $ bin/django migrate $ bin/django runserver
  • 21. Git Repository • Git Flow (http://nvie.com/posts/a-successful-git-branching-model/) – master • Always tagged with a version • To be deployed – develop • Next version currently in development – release/1.x.x • A release being prepared • Merges into master with tag 1.x.x
  • 22.
  • 23. How are we deploying? • Configuration: – Apache2 + mod_wsgi – MySQL – Optimize only when necessary (varnish, memcache, ...) • Jenkins pipeline – Perform a buildout – Generate .deb file – Upload to Infrastructure Package Repository – Triggers a Puppet run
  • 24. Onderwijstips • Three applications – Tips (front-end for users) – Editors (back-end for tip author) – Migration (plomino importer) • Features: – Haystack search indexing (django-haystack) – User authentication (django-cas) – MediaMosa Integration (django-mediamosa) – Tagging (django-taggit) – Ugent Theming (django-ugent) • Buildout (Thx Bert!) • Monitoring via Sentry • Database schema migration management via South