R includewwwexamplecomhttpconfigurls

We have not created any views in our application, but we can already define the URL mapping in the application-specific urls.py, which needs to be created in the application directory httpconfig. The majority of the work is going to be done in the administration interface, so the application's interaction with the outside world is fairly limited. It'll respond to two requests only: if nothing is specified on the URL path, the view should return all virtual hosts in a plain-text format. If an integer is specified, it'll return only the section of the configuration file for that particular Virtual Host. This will be used in the administration interface. In the httpadmin directory, create the urls. py file shown in Listing 5-3.

Listing 5-3. The application-specific URL mapping from django.conf.urls.defaults import *

urlpatterns = patterns('www_example_com.httpconfig.views', (r'A$', 'full_config'),

This configuration means that there is no application-specific part in the URL—all requests to the root location will be forwarded to our application. If you need to "hide" this application behind a certain path in the URL, please refer back to Chapters 3 and 4 for details on how to do that.

In addition to this configuration, you also have to define the view method; otherwise, the Django URL parser may complain about the undefined view. Create the following method in the views. py file in the application directory:

def full_config(request): return

■Tip If you get any errors when you navigate to the newly created web site, make sure that all files and directories in the project directory and the project directory itself are owned by the apacheor httpduser. Also note that if you make any changes to the Python files in your project directory, you will need to restart the Apache daemon, so that the requests will be served by the new code rather than the old, which may still be cached in memory.

Was this article helpful?

0 0

Post a comment