Monday, September 7, 2015

Intro to Django - Building a To-Do List

Django is a powerful web framework, created in Python, which follows the DRY (Don't repeat yourself), and batteries included philosophies. It allows for rapid website development by providing a wide range of tools and shortcuts out of the box. Django is extremely fast and flexible - even faster than all of the PHP frameworks available. In this article, I'll introduce you to Django by showing you how to build a simple to-do list.


As stated above, Django follows the batteries included philosophy. PHP frameworks such as Code Igniter try and strip all of the "unnecessaries" out for maximum performance; but Django can include all of these out of the box and still be high performance because of its modular design (If you don't call include feature XX then it isn't included; so it doesn't slow the script down). Here are some of the most notable features:
  • User/Authentication system
  • Automatic RSS generation
  • GIS
  • Automatically generated Admin interface
  • Generic views (more on this later)
  • Three level caching system
  • Powerful template system
  • Comments
Django runs on an MTV (Model Template View) system (Not the television channel). This is different from MVC.
  • Model. The model sets out the schema for our database. Unlike PHP frameworks, you don't write your queries here. Using Django's ORM you declare the fields, field types and any additional data such as Meta information.
  • View. In the View, you set all of your code logic. You may need to pull some results from the database or manipulate some strings. The view expects a request and a response. The response is typically an http redirect, http error (404), or a call to load a template. When loading a template you usually pass some data through - most likely, results from a database query.
  • Template. The template is the plain HTML code with Django's custom Template 'language' (similar to smarty) in it. You look and iterate just like you would with any other language.

No comments:

Post a Comment