SlideShare a Scribd company logo
1 of 20
Download to read offline
django

python powered MVC framework
Presentation topics

● why python and why django?
● what is MVC?
● the M in the django framework
● the V in the django framework
● and the C in the django framework
● django admin
why python and why django?

#1, why python?
 ● python is a "natural" OO language;
 ● python has functional capabilities;
 ● "batteries included"!!

#2, why django?
 ● uses python (ahhh!);
 ● interfaces for common actions (dry);
 ● pluggable apps;
 ● you have more time to CREATE!
 ● you had VALUE to you products;
what is MVC?

A software development pattern where the business logic is
separated from the UI.

In web development:

 ● (M)odel: the business logic/rules off the application (mostly
   the DB);

 ● (V)iew: the (x)html rendered and presented to the user;

 ● (C)ontroller: the handler that receives GET or POST
   requests, works over the domain object and retrieves a
   response to the user;
what is MVC?

In the Django framework, things are a little bit different...



                      Welcome to "MTV"!!
                    (Model - Template - View)
the M in the django framework
the M in the django framework

Not much different from the other M...

 ● It holds the business logic/rules;

 ● It is related with the DB;

 ● Describes the DB as classes of objects using a mapper
   (ORM);

 ● It holds methods to retrieve data;
the M in the django framework
Example:
from django.db import models

class Company(models.Model):
    name = models.CharField(_("Company name"), max_length=64)
    phone = models.CharField("URL", max_length=32)
    fax = models.CharField("Fax", max_length=32, null=True, blank=True)
    email = models.EmailField("E-mail", max_length=32, null=True, blank=True)
    ceos = models.ForeignKey('entities.Ceo')

    class Meta:
        ordering = ['name']
        db_table = 'company'
        verbose_name = _('Company')
        verbose_name_plural = _('Companies')

    # Return company's administrators
    def get_ceos(self):
        return self.ceos

    # Returns an instance in a human-readable format
    def __unicode__(self):
        return self.name
the V in the django framework
the V in the django framework

A view, in django, has two parts:

#1 A callback that:

 ● is a normal python method that always receive an HTTP
   request object...

 ● ... and always returns an HTTP response object;

 ● describes which data is presented;
the V in the django framework

#2 An URLconf:

 ● that is a mapper between url's and the view callbacks;

 ● that is described by regexes;
the V in the django framework

We can also include the templates here, since it is intrinsically
linked to the view callbacks.

 ● Django has its own template system/language;

 ● It is pythonic, but very stricted;

 ● Organized by tags;

 ● Focus on how you display data;

 ● You can write your own set of tags;
the V in the django framework
Example of a view:
from django.shortcuts import render_to_response
def property_details(request, id):
   try:
      c = {}
      c.update(csrf(request))
      property = Property.objects.get(pk=id)
      c['property'] = property
   except Property.DoesNotExist:
      raise Http404
   return render_to_response('properties/property_details.html', c)

Example of an URLconf:
urlpatterns = patterns('properties.views',
   (r'^(?P<id>d+[a-z]*)', 'property_details'),
)
the V in the django framework

Example of a template:
{% extends "base.html" %}
{% load i18n %}

{% block highlights %}
{% include "horizontal_search.html" %}
<div style="margin-top: 25px;"></div>
{% endblock %}
{% block content %}
  <div style="padding-left: 9px; padding-right: 6px;">
  <div id="text_wrapper">
<h4>{% trans "About" %} {{ property.reference }}</h4>
{{ property.description }}
  </div>
{% endblock %}
the C in the django framework
the C in the django framework
Possibly the most complex part... Basically it's all the django
framework! This includes:

 ● modules that are responsible for user authentication...

 ● modules that prevents CSRF's...

 ● that are responsible for the website language (i18n, l7n);

 ● etc...

It's all the machinery between an URLconf and a view. Those
modules are called middleware.
django admin
django admin

django admin is a very usefull app that allows you to save a lot
of time.

 ● Uses class attributes to create forms;

 ● Common methods included (add, edit, remove);

 ● Complete admin interface that can be changed;

 ● User management;
django admin
Default objects list
django admin
Default add form

More Related Content

What's hot

Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
Automation - fabric, django and more
Automation - fabric, django and moreAutomation - fabric, django and more
Automation - fabric, django and moreIlian Iliev
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
Django Seminar 08/17/2013
Django Seminar 08/17/2013Django Seminar 08/17/2013
Django Seminar 08/17/2013Trinh Nguyen
 
Agile Development With Hobo
Agile Development With HoboAgile Development With Hobo
Agile Development With HoboEvarist Lobo
 
Best Tools for first time Odoo Development
Best Tools for first time Odoo DevelopmentBest Tools for first time Odoo Development
Best Tools for first time Odoo DevelopmentOdoo
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplicationolegmmiller
 
PyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document GenerationPyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document Generation용선 이
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perlDean Hamstead
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programingLukas Lesniewski
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010singingfish
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perlDean Hamstead
 
Efficient Django
Efficient DjangoEfficient Django
Efficient DjangoDavid Arcos
 

What's hot (20)

Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Automation - fabric, django and more
Automation - fabric, django and moreAutomation - fabric, django and more
Automation - fabric, django and more
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Django Seminar 08/17/2013
Django Seminar 08/17/2013Django Seminar 08/17/2013
Django Seminar 08/17/2013
 
Django Best Practices
Django Best PracticesDjango Best Practices
Django Best Practices
 
App Engine
App EngineApp Engine
App Engine
 
Django
DjangoDjango
Django
 
Agile Development With Hobo
Agile Development With HoboAgile Development With Hobo
Agile Development With Hobo
 
Best Tools for first time Odoo Development
Best Tools for first time Odoo DevelopmentBest Tools for first time Odoo Development
Best Tools for first time Odoo Development
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
django
djangodjango
django
 
PyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document GenerationPyCon Korea 2019 REST API Document Generation
PyCon Korea 2019 REST API Document Generation
 
Getting big without getting fat, in perl
Getting big without getting fat, in perlGetting big without getting fat, in perl
Getting big without getting fat, in perl
 
Ant
Ant Ant
Ant
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
 
J Query
J QueryJ Query
J Query
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 
Getting modern with logging via log4perl
Getting modern with logging via log4perlGetting modern with logging via log4perl
Getting modern with logging via log4perl
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 

Similar to A gentle intro to the Django Framework

Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics PresentationShrinath Shenoy
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Python Ireland
 
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
 
TangoWithDjango - ch8
TangoWithDjango - ch8TangoWithDjango - ch8
TangoWithDjango - ch8Asika Kuo
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsAshishMishra308598
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030Kevin Wu
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjsgdgvietnam
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheetLam Hoang
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxbestboybulshaawi
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesLeonardo Fernandes
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 

Similar to A gentle intro to the Django Framework (20)

Web development with django - Basics Presentation
Web development with django - Basics PresentationWeb development with django - Basics Presentation
Web development with django - Basics Presentation
 
Django
DjangoDjango
Django
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)Google App Engine in 40 minutes (the absolute essentials)
Google App Engine in 40 minutes (the absolute essentials)
 
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
 
TangoWithDjango - ch8
TangoWithDjango - ch8TangoWithDjango - ch8
TangoWithDjango - ch8
 
Django Frequently Asked Interview Questions
Django Frequently Asked Interview QuestionsDjango Frequently Asked Interview Questions
Django Frequently Asked Interview Questions
 
django_introduction20141030
django_introduction20141030django_introduction20141030
django_introduction20141030
 
Discovering Django - zekeLabs
Discovering Django - zekeLabsDiscovering Django - zekeLabs
Discovering Django - zekeLabs
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
 
Tango with django
Tango with djangoTango with django
Tango with django
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptx
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 

A gentle intro to the Django Framework

  • 2. Presentation topics ● why python and why django? ● what is MVC? ● the M in the django framework ● the V in the django framework ● and the C in the django framework ● django admin
  • 3. why python and why django? #1, why python? ● python is a "natural" OO language; ● python has functional capabilities; ● "batteries included"!! #2, why django? ● uses python (ahhh!); ● interfaces for common actions (dry); ● pluggable apps; ● you have more time to CREATE! ● you had VALUE to you products;
  • 4. what is MVC? A software development pattern where the business logic is separated from the UI. In web development: ● (M)odel: the business logic/rules off the application (mostly the DB); ● (V)iew: the (x)html rendered and presented to the user; ● (C)ontroller: the handler that receives GET or POST requests, works over the domain object and retrieves a response to the user;
  • 5. what is MVC? In the Django framework, things are a little bit different... Welcome to "MTV"!! (Model - Template - View)
  • 6. the M in the django framework
  • 7. the M in the django framework Not much different from the other M... ● It holds the business logic/rules; ● It is related with the DB; ● Describes the DB as classes of objects using a mapper (ORM); ● It holds methods to retrieve data;
  • 8. the M in the django framework Example: from django.db import models class Company(models.Model): name = models.CharField(_("Company name"), max_length=64) phone = models.CharField("URL", max_length=32) fax = models.CharField("Fax", max_length=32, null=True, blank=True) email = models.EmailField("E-mail", max_length=32, null=True, blank=True) ceos = models.ForeignKey('entities.Ceo') class Meta: ordering = ['name'] db_table = 'company' verbose_name = _('Company') verbose_name_plural = _('Companies') # Return company's administrators def get_ceos(self): return self.ceos # Returns an instance in a human-readable format def __unicode__(self): return self.name
  • 9. the V in the django framework
  • 10. the V in the django framework A view, in django, has two parts: #1 A callback that: ● is a normal python method that always receive an HTTP request object... ● ... and always returns an HTTP response object; ● describes which data is presented;
  • 11. the V in the django framework #2 An URLconf: ● that is a mapper between url's and the view callbacks; ● that is described by regexes;
  • 12. the V in the django framework We can also include the templates here, since it is intrinsically linked to the view callbacks. ● Django has its own template system/language; ● It is pythonic, but very stricted; ● Organized by tags; ● Focus on how you display data; ● You can write your own set of tags;
  • 13. the V in the django framework Example of a view: from django.shortcuts import render_to_response def property_details(request, id): try: c = {} c.update(csrf(request)) property = Property.objects.get(pk=id) c['property'] = property except Property.DoesNotExist: raise Http404 return render_to_response('properties/property_details.html', c) Example of an URLconf: urlpatterns = patterns('properties.views', (r'^(?P<id>d+[a-z]*)', 'property_details'), )
  • 14. the V in the django framework Example of a template: {% extends "base.html" %} {% load i18n %} {% block highlights %} {% include "horizontal_search.html" %} <div style="margin-top: 25px;"></div> {% endblock %} {% block content %} <div style="padding-left: 9px; padding-right: 6px;"> <div id="text_wrapper"> <h4>{% trans "About" %} {{ property.reference }}</h4> {{ property.description }} </div> {% endblock %}
  • 15. the C in the django framework
  • 16. the C in the django framework Possibly the most complex part... Basically it's all the django framework! This includes: ● modules that are responsible for user authentication... ● modules that prevents CSRF's... ● that are responsible for the website language (i18n, l7n); ● etc... It's all the machinery between an URLconf and a view. Those modules are called middleware.
  • 18. django admin django admin is a very usefull app that allows you to save a lot of time. ● Uses class attributes to create forms; ● Common methods included (add, edit, remove); ● Complete admin interface that can be changed; ● User management;