The core building blocks of Django

Yesterday we description at a high level what Django is. Today, we're going to briefly walk through the core components that will exist is every Django application.

First up is a list of URL patterns. These can be static, for example /about or have dynamic aspects such as the username for a profile page /profile/<username>. Django has these in a list and will match against the first pattern. This is often a common gotcha for beginners as they create URLs in the wrong order so execute the unexpected code.

URLs are linked to the second component, Views. This is the main place where you write business logic, at least to begin with. A View takes a request and arguments from the URL and needs to return a response. The sky's the limit in views you can do what you like (more on this another day).

Finally, there are templates. While strictly not needed, templates make it easy to write the actual HTML that is returned to the client and sprinkle in the data collected from the view. Templates are rendered on the server and sent back to the browser to display.

With those 3 components you can build simple Django websites, however it gets more interesting when you can store and query data from database, which will be tomorrow's post.