April 2018
Beginner to intermediate
440 pages
11h 36m
English
The arena view accepts the request object and then instantiates an ArenaForm object to gather the data needed to respond to the request. A query of the Arenas model objects and its values_list method creates a Python list that contains tuples with the ID and name of every arena. The request method (either GET or POST) is used in a conditional to determine the appropriate response.
If a GET request is received (that is, the web page is first opened), a random arena object is generated and passed to the template, which shows the arena on the included map. To get a random arena, we use the list of arena names and IDs (values). Once the list is generated, a list comprehension is used to generate a new list containing arena names. ...