url
helper takes a second parameter, which is the method to send the request to. In the homepage example, if the URL matches an empty string, the request is routed to theme.home
. The definition for theme.home
lives in ubyssey/views/main.py:context
and the final return
statement.ubyssey.ca
folder so that all the files are in one place.File > Add Project Folder
and select the ubyssey.ca
folder.home
method is responsible for sending an HTML response back to the user, but before it can do that, it has to fetch and prepare all the data it needs. Most of the calls to ArticleHelper
fetch data from our database, which is then added to the context
structure at the end of the method.context
structure.context
data structure is a primitive type called a dictionary
, which is just Python's version of a hash table. It simply creates a map of keys to values:context
data structure to include a random number from 1 to 10.home
method makes a call to the render
method, which (you guessed it!) renders the final output of the homepage. You'll notice that it takes three arguments:request
- the Django request object, stores information about the incoming requesthomepage/base.html
- the template file to usecontext
- the context to pass to the templaterender
method loads the homepage/base.html
template and returns the result of rendering that template with the given context.templates/homepage/base.html
so that it prints the following at the top of the page:YOUR RANDOM NUMBER HERE