Writing views

Everything is finally set to write our views. Open up views.py from the Arenas application folder within an IDE. Import the required libraries, models, forms, and modules:

from django.shortcuts import render, redirectfrom django.http import HttpResponse, HttpResponseNotFoundfrom .models import US_States, Counties, Districts, Arenasfrom .forms import ArenaFormfrom django.views.decorators.http import require_http_methodsimport random

Next, we will create two views—index and arenaand one non-view function called queryarena. These match with the URLs we added to urls.py. The return from the index function is very simple—it will redirect to the function arena. For the views, a decorator is used to determine the HTTP request methods ...

Get Mastering Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.