In this chapter from Django Unleashed, Andrew Pinkham examines how the two parts of the Controller, URL configurations and views, interact. He then uses the cumulative knowledge to build dynamic webpages.

5.1 Introduction

In Chapter 2: Hello World: Building a Basic Webpage in Django, we saw that the Controller is the only part of Django actually required to make a webpage (the relevant diagram is reprinted in Figure 5.1). However, we immediately ran into problems: we had no way to easily fetch and format data. Because the main function of websites revolves around data, the Controller is often described as the glue between Model and View despite the Controller’s independence.

In this chapter, we return to the Controller, seen earlier in Chapter 2 and Chapter 4: Rapidly Producing Flexible HTML with Django Templates. We first re-examine how the two parts of the Controller, URL configurations and views, interact. We then use the cumulative knowledge we have gained to build dynamic webpages.

The Controller is central to Django and comes with a number of options. Once we have the basics, we look at how to handle problems that occur in views. We then look at ways to more rapidly code views (at the cost of developer control). Coding views enable us to very quickly build all the webpages for our site.

Before we finish the chapter, we also examine two special methods for creating Controllers, which become important later in the book.

This chapter assumes knowledge of HTTP and regular expressions. Primers on both are provided in Appendix A and Appendix E, respectively.