Django Tech Talk
By Amanpreet Singh
amanpreet.singh1@hindustantimes.com
Why Django?
● Fully loaded.
● Reassuringly secure.
● Exceedingly scalable.
● Incredibly versatile.
● Ridiculously fast.
Django at a
glance.
● Design your model
● Enjoy the free API
● A dynamic admin
interface
● Design your URLs
● Write your views
● Design your templates
IS IT MTV OR MVC??
What do you think?
The model layer
❖ Models
❖ QuerySets
❖ Migrations
❖ Managers
Models
❖ Setup
❖ Field Options(primary_key, null, blank)
❖ Relationships
❖ Backward Relationship( How it works?)
❖ Field Name Restrictions
❖ Meta Options
Models Cont.
❖ Model Attributes (Manager)
❖ Model Methods
❖ Model Inheritance
➢ Abstract Base Class
➢ Derived Class
➢ Multi-table Inheritance
➢ Multiple Inheritance
QuerySets
It can be filtered, sliced etc generally without actually hitting
the database.
No DB activity actually occurs until you do something to
evaluate queryset.
Some Methods
that return new
QuerySet
● filter( )
● all( )
● select_related( )
● values( )
● values_list ( )
● exclude( )
● only( )
● order_by( )
Some Methods
that do not
return new
QuerySet
● get ( )
● get_or_create( )
● create( )
● delete( )
● update( )
● count( )
Field Lookups
● exact
● icontains
● contains
● in
● gte
● lte
● gt
Migrations And Managers
Migrations - A way of propagating changes you make to your
models.
Managers - A manager is the interface through which DB
query operations are provided to django model.
The view layer
❖ URL
❖ Error Handling (Built In Views)
❖ Class Based Views
How Django processes a request?
● ROOT_URLCONF
● urlpatterns
● Runs in order and stops when matches.
● Once matches, django imports and calls the given view.
● If no path matches, exception is raised during any point in
the process.
Error Handling
❖ handler400 ( Bad request)
❖ handler 403 ( Forbidden)
❖ handler 404 ( Page not
Found)
❖ handler 500 (Server Error)
Class Based
Views
● Seperate get, post method
instead of conditional branching
● Multiple Inheritance(Using
Mixins)
● Decorating class-based Views
The template layer
❖ Language overview
❖ Built-in tags and filters (block, comment, lower, firstof)
❖ Custom tags and filters
Django Request
Response Cycle and
The Middlewares
WSGI
Connecting
Web Server
and
Web Framework
A gatekeeper between your web
server and Django Application.
Between the server and the application lie the
middlewares. You can think of middlewares as
a series of bidirectional filters.
Middlewares
The Big Picture — Data Flow
Middlewares ❏ process_request
❏ process_view
❏ process_exception
❏ process_response
Middleware Methods
Context Processors
Thank You

Django

  • 1.
    Django Tech Talk ByAmanpreet Singh amanpreet.singh1@hindustantimes.com
  • 2.
    Why Django? ● Fullyloaded. ● Reassuringly secure. ● Exceedingly scalable. ● Incredibly versatile. ● Ridiculously fast.
  • 3.
    Django at a glance. ●Design your model ● Enjoy the free API ● A dynamic admin interface ● Design your URLs ● Write your views ● Design your templates
  • 4.
    IS IT MTVOR MVC?? What do you think?
  • 6.
    The model layer ❖Models ❖ QuerySets ❖ Migrations ❖ Managers
  • 7.
    Models ❖ Setup ❖ FieldOptions(primary_key, null, blank) ❖ Relationships ❖ Backward Relationship( How it works?) ❖ Field Name Restrictions ❖ Meta Options
  • 8.
    Models Cont. ❖ ModelAttributes (Manager) ❖ Model Methods ❖ Model Inheritance ➢ Abstract Base Class ➢ Derived Class ➢ Multi-table Inheritance ➢ Multiple Inheritance
  • 9.
    QuerySets It can befiltered, sliced etc generally without actually hitting the database. No DB activity actually occurs until you do something to evaluate queryset.
  • 10.
    Some Methods that returnnew QuerySet ● filter( ) ● all( ) ● select_related( ) ● values( ) ● values_list ( ) ● exclude( ) ● only( ) ● order_by( )
  • 11.
    Some Methods that donot return new QuerySet ● get ( ) ● get_or_create( ) ● create( ) ● delete( ) ● update( ) ● count( )
  • 12.
    Field Lookups ● exact ●icontains ● contains ● in ● gte ● lte ● gt
  • 13.
    Migrations And Managers Migrations- A way of propagating changes you make to your models. Managers - A manager is the interface through which DB query operations are provided to django model.
  • 14.
    The view layer ❖URL ❖ Error Handling (Built In Views) ❖ Class Based Views
  • 15.
    How Django processesa request? ● ROOT_URLCONF ● urlpatterns ● Runs in order and stops when matches. ● Once matches, django imports and calls the given view. ● If no path matches, exception is raised during any point in the process.
  • 16.
    Error Handling ❖ handler400( Bad request) ❖ handler 403 ( Forbidden) ❖ handler 404 ( Page not Found) ❖ handler 500 (Server Error)
  • 17.
    Class Based Views ● Seperateget, post method instead of conditional branching ● Multiple Inheritance(Using Mixins) ● Decorating class-based Views
  • 18.
    The template layer ❖Language overview ❖ Built-in tags and filters (block, comment, lower, firstof) ❖ Custom tags and filters
  • 19.
    Django Request Response Cycleand The Middlewares
  • 20.
    WSGI Connecting Web Server and Web Framework Agatekeeper between your web server and Django Application.
  • 21.
    Between the serverand the application lie the middlewares. You can think of middlewares as a series of bidirectional filters. Middlewares
  • 22.
  • 23.
    Middlewares ❏ process_request ❏process_view ❏ process_exception ❏ process_response Middleware Methods
  • 24.
  • 25.