Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django 101

Boris Feld
September 28, 2016

Django 101

Boris Feld

September 28, 2016

More Decks by Boris Feld

Other Decks in Programming


  1. GOODWILL PRINCIPLE • Everyone did its best in the the

    limits of their knowledge and ability at a certain time • Everyone has a life outside this classroom but will do his best for this not to interfere with the class. • Every assessment has a goal: identifying room for improvement.
  2. - Boris FELD « Code is a side-product of application.

    Communication skills are much more valuable than coding one. »
  3. WEB FRAMEWORK • Web Frameworks are a toolset designed to

    support the development of web applications. • Web Frameworks usually provides functions for common tasks like database access, HTML templating or session management. • They speed the development of web applications by taking care of common tasks.
  4. DJANGO • Most popular Python web framework. • First version

    in July 2005. • The framework was named after guitarist Django Reinhardt.
  5. CONCEPT HTTP REQUEST GET / HTTP/1.1 Host: Connection: keep-alive

    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 Hello: Nancy
  6. CONCEPT HTTP RESPONSE HTTP/1.0 200 OK Date: Sun, 25 Sep

    2016 10:58:40 GMT Server: WSGIServer/0.1 Python/2.7.12 X-Frame-Options: SAMEORIGIN Content-Type: text/html <!DOCTYPE html> <html lang="en"><head> 1. Version de HTTP 2. Status code (200 OK) 3. Headers 4. Body
  7. CONCEPT STATUS CODE • Indicates the presence of errors or

    validity of a response. • https://en.wikipedia.org/wiki/ List_of_HTTP_status_codes • https://http.cat/ • https://httpstatusdogs.com/
  8. CONCEPT ORM • Object Relational Mapping is a technique to

    access relational data through object-oriented code. • It abstract part of the relational complexity required to access data.
  9. CONCEPT ORM • Instead of doing: • You can do:

    cursor = connection.Cursor() cursor.query('SELECT "polls_question"."id", "polls_question"."question_text", "polls_question"."pub_date" FROM "polls_question" WHERE "polls_question"."id" = ?', 1) result = cursor.fetchone() q = Question.objects.get(pk=1)
  10. CONCEPT ADMIN INTERFACE • While website often a presentation of

    the data for the customers (front-end), we generally need one for administrating the website, like resetting a password for an user. • Django comes up with an almost free admin, so enjoy!
  11. CONCEPT CONTROLLER • Process the HTTP Request • Call the

    model for getting data • Choose an acceptable view
  12. CONCEPT VIEW • Format the data for the user in

    one format • It’s usually an HTML page
  13. WHAT BENEFITS? • For the model ? • For the

    view ? • For the controller ?
  14. WHAT BENEFITS? • For the model ? • Other sources

    of data (file system, nosql, cache, …) • For the view ? • Other formats of presentation (json, xml, cvs, …) • For the controller ? • Can be left untouched when other parts change.
  15. CONCEPT CRUD • Most applications behavior can be simplified to:

    • Create • Read • Update • Delete
  16. CONCEPT BUSINESS LOGIC • Most website value reside in their

    business logic and capabilities to make actions. • Basic CRUD actions are much less valuable but shouldn’t be overlooked, better let Django handle these situations for you. • You better wrote less code but more valuable code.