Projects vs. apps
What’s the difference between a project and an app? 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.
Each model is a Python class that subclasses django.db.models.Model.
Each attribute of the model represents a database field.
Model metadata (non-field information) goes in an inner class named Meta.
Metadata used for Django’s admin site goes into an inner class named Admin
Executing Custon SQL
def my_custom_sql(self):
from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
row = cursor.fetchone()
return row
How Django processes a request
When a user requests a page from your Django-powered site, this is the algorithm the system follows to determine which Python code to execute:
Django looks at the ROOT_URLCONF setting in your settings file. This should be a string representing the full Python import path to your URLconf. For example: "mydjangoapps.urls".
Django loads that Python module and looks for the variable urlpatterns. This should be a Python list, in the format returned by the function django.conf.urls.defaults.patterns().
Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.
Once one of the regexes matches, Django imports and calls the given view, which is a simple Python function. The view gets passed a request object as its first argument and any values captured in the regex as remaining arguments.
Showing posts with label request. Show all posts
Showing posts with label request. Show all posts
Friday, November 23, 2007
Subscribe to:
Posts (Atom)