PySIG Django Presentation - Feb. 22, 2007
Dave Rowell, Appropriate Solutions, Inc., Peterborough, NH
drowell@appropriatesolutions*REMOVE*.com
Definition of Django
From the Django site: "Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design."
Supporting examples:
- Simple (for a programmer) to set up and get going.
- Uses and allows loosely coupled components.
- Encourages well-formed urls.
- MVC-ish design separates data, business logic and appearance: Model (data design), View (business logic), Template (presentation).
Why I like Django
Good use of Python. Except for the templates, the components you work with are all Python code.
The framework is high-level with lots of useful components, but it's also flexible with hooks to get in and do whatever you need to do. However, more and more I find that when I need to do something,
someone's already done it and left me well-designed tools to do the same.
What Appropriate Solutions uses Django for
* Site to display current and historical credit exchange rates. It was my first Django app and also complex enough to make Django's automatic admin interface uncomfortable. I think I'd like to come back to this app after more experience and see if I can make it fit better. This app required writing several largish SQL queries.
* An internal hour-tracking application (in development).
* Low-cost e-commerice web sites. A good fit for Django. I actually found myself removing code and files as I learned to use the built-in Django tools. As our web store app becomes more complicated, we may consider converting to Satchmo, a Django-based e-commerce project with more complicated features (www.satchmoproject.com).
Django features
From "Django for Non-Programmers" (link below):
- Administrative interface (for adding/deleting/modifying items in the database)
- Database connectivity (several supported databases – PostgreSQL, MySQL, Oracle in the works - no SQL needed)
- Authentication and authorization (users, groups, and permissions)
- URL configuration (for making simple, clean URLs)
- Internationalization (makes localization easy)
- Feed syndication (RSS/Atom)
- Comments on any type of object (both anonymous comments, which Django calls “free comments” and comments that require registration)
- Flat pages (simple HTML content stored in the database and passed into a template)
Also (from my programmer perspective):
- Builds your database for you from your model classes (models.py)
- Development web server that works as you modify code and provides debug information
- Supports scalable hosting (Apache with ModPython, lighttpd)
- Many content caching options
- Projects can consist of several pluggable applications
- Generic views that handle common data models (category/item, date archive)
- Extensible template language
The basic Django app components
settings.py - general control over environment and what's included in your web project
models.py - defines your data model - from this Django will build a complete DB schema
urls.py - regular expressions that map URLs to views views.py - Python programs that build the data context of a web page and choose the template to display it
templates – html page templates with {{ variables }} and {% block tags %} that provide display logic (loops, if-then)
Django Links
- James Bennet's (Django developer) enlightening blog entries on Django,
http://www.b-list.org/feeds/categories/django
- Django for Non-Programmers, Django web designer's (Jeff Croft, World
Online) point of view,
http://www2.jeffcroft.com/blog/2006/may/02/django-non-programmers/