
Django is an open source Python web framework that uses a variation of the MVC architectural pattern, called MTV for Model-Template-View. Having used Django for quite a few projects now, I have grown rather fond of it, despite some annoying aspects. Development using Django is very easy and painless, allowing for rapid prototyping and development.
Django can run on top of a variety of standard web servers, such as Apache, lighttpd and Cherokee. It also ships with a development web server, but that is for testing purposes only. I personally used Apache with mod-wsgi, instructions on how to set that up here. Django doesn’t serve media files itself; it leaves that to whichever web server you choose. It is reccommended that the media isn’t served up by the same web server, but I made them both live on the same server.
Other than a few configuration differences inside the main settings.py file, Django can use almost any sort of database without any differences in terms of actually coding the application. The settings.py file will have all of the database information, such as type and path and authentication credentials and the like. I will talk more about accessing the database in a little bit. Inside the settings.py is also where a list of all the “installed_apps” is kept. An app is a Web application that does something—e.g., a weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects. http://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs is a very good tutorial that I used to get my feet wet with django
Also in the root directory is urls.py which has a list of url patterns in regex and the app, and the function within that app’s view, that they each associate with.
The manage.py file inside the main directory is used for many purposes. python manage.py startapp [appname] can be used to automatically generate a new app directory with some pre-created files. python manage.py sql [appname]... can be used to turn the model definitions within each app and turn that into CREATE TABLE sql statements. python manage.py syncdb can be used to automatically update the database that is assoicated with project to the model definitions, used after the manage.py sql command has been run for all of the apps.
When an app gets created by manage.py, a few files will be automatically created for you. models.py is where all of the definitions for the object-relational mapping is declared. views.py is where the handlers for each url request is declared. While one could have the entire output to the client stored in the views.py, it is generally best practice to use the view to do all of the database and computational work, and then pass off the presentation to the tempates. The tutorial link that I included earlier will have much more detail on how that works.
Templates are basically html files that can also include {{ }} or {% %} directives. They’re responsible for all of the presentation.
* Please be aware that all comments are moderated.
DJ flower | 12:43 AM December 23, 2011
yea soy DJ