django sessions for beginners

def index(request):
    ...

    num_authors = Author.objects.count()  # The 'all()' is implied by default.
    
    # Number of visits to this view, as counted in the session variable.
    num_visits = request.session.get('num_visits', 0)
    request.session['num_visits'] = num_visits + 1

    context = {
        'num_books': num_books,
        'num_instances': num_instances,
        'num_instances_available': num_instances_available,
        'num_authors': num_authors,
        'num_visits': num_visits,
    }
    
    # Render the HTML template index.html with the data in the context variable.
    return render(request, 'index.html', context=context)

Here is what the above code is Doing:
1. We’re adding a new variable to the context dictionary called num_authors.
2. We’re adding a new variable to the context dictionary called num_visits.
3. We’re adding a new variable to the context dictionary called num_books.
4. We’re adding a new variable to the context dictionary called num_instances.
5. We’re adding a new variable to the context dictionary called num_instances_available.
6. We’re adding a new variable to the context dictionary called num_authors.
7. We’re adding a new variable to the context dictionary called num_visits.
8. We’re rendering the index.html template with the context dictionary.