Django Processes a Request
Django Processes a Request
when
we run the Django development server and make requests to Web pages:
The command python manage.py runserver imports a file called settings.py from the
same directory. This file contains all sorts of optional configuration for this particular Django
instance, but one of the most important settings is ROOT_URLCONF. The ROOT_URLCONF setting
tells Django which Python module should be used as the URLconf for this Web site.
Remember when django-admin.py startproject created the files settings.py and
urls.py? Well, the autogenerated settings.py has a ROOT_URLCONF that points to the
autogenerated urls.py. Convenient.
·
When a request comes in—say, a request to the URL /time/—Django loads the URLconf pointed
to by the ROOT_URLCONF setting. Then it checks each of the URLpatterns in that URLconf in order,
comparing the requested URL with the patterns one at a time, until it finds one that matches. When it
finds one that matches, it calls the view function associated with that pattern, passing an
HttpRequest object as the first parameter to the function. (More on HttpRequest later.)
·
· The view function is responsible for returning an HttpResponse object.
when
we run the Django development server and make requests to Web pages:
The command python manage.py runserver imports a file called settings.py from the
same directory. This file contains all sorts of optional configuration for this particular Django
instance, but one of the most important settings is ROOT_URLCONF. The ROOT_URLCONF setting
tells Django which Python module should be used as the URLconf for this Web site.
Remember when django-admin.py startproject created the files settings.py and
urls.py? Well, the autogenerated settings.py has a ROOT_URLCONF that points to the
autogenerated urls.py. Convenient.
·
When a request comes in—say, a request to the URL /time/—Django loads the URLconf pointed
to by the ROOT_URLCONF setting. Then it checks each of the URLpatterns in that URLconf in order,
comparing the requested URL with the patterns one at a time, until it finds one that matches. When it
finds one that matches, it calls the view function associated with that pattern, passing an
HttpRequest object as the first parameter to the function. (More on HttpRequest later.)
·
· The view function is responsible for returning an HttpResponse object.
Comments
Post a Comment