Previous Page Next Page

Hour 4. Creating the Initial Views

What You'll Learn in This Hour

  • How to configure the initial URLconf file

  • How to handle HTTP requests

  • How to display web pages using the HttpResponse object

  • How to configure URL patterns to enable a view

  • How to add URL-based arguments to a view

This hour shows you how to create and configure the initial views for your projects. Django requires some initial configuration to enable views. As soon as views are enabled through the URLconf file, they are simple to use and powerful.

This hour also shows you how to handle HTTP requests and send HTTP responses directly from your views.

Setting Up the URLconf File

URL configuration of a Django website begins with the ROOT_URLCONF setting in the settings.py file. The ROOT_URLCONF setting points to a file that contains a series of URL patterns that define how the website will respond to various addresses.

The value of the ROOT_URLCONF setting in the iFriends projects initially is set to the following:

ROOT_URLCONF = 'iFriends.urls'

The syntax for the ROOT_URLCONF setting is as follows:

sitename.location.(URLConf filename without the .py extension)

The best way to illustrate the syntax is to use some examples. Let's say we want to set the root location of the URLconf file to the People directory in our iFriends project and that we want the name of the URLconf file to be PeopleURLS.py. We would use the following value for ROOT_URLCONF to point to that location:

ROOT_URLCONF = 'iFriends.People.PeopleURLS'

Previous Page Next Page