catalog/views.py
def index(request):
    """View function for home page of site."""

    # Generate counts of some of the main objects
    num_books = Book.objects.all().count()
    num_instances = BookInstance.objects.all().count()

    # Available books (status = 'a')
    num_instances_available = BookInstance.objects.filter(status__exact='a').count()

    # The 'all()' is implied by default.
    num_authors = Author.objects.count()

    num_genres = Genre.objects.count()

    num_books_withWord = Book.objects.filter(title__contains='Spire').count()

    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_genres': num_genres,
        'num_books_withWord': num_books_withWord,
        'num_visits': num_visits,
    }

    # Render the HTML template index.html with the data in the context variable
    return render(request, 'index.html', context=context)
View function for home page of site.
View function for home page of site.
View function for home page of site .
def index(request):
    num_books = Book.objects.all().count()
    num_instances = BookInstance.objects.all().count()
    num_instances_available = BookInstance.objects.filter(status__exact='a').count()
    num_authors = Author.objects.count()
    num_genres = Genre.objects.count()
    num_books_withWord = Book.objects.filter(title__contains='Spire').count()
    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_genres': num_genres,
        'num_books_withWord': num_books_withWord,
        'num_visits': num_visits,
    }
    return render(request, 'index.html', context=context)
def index ( request ) : num_books = Book . objects . all ( ) . count ( ) num_instances = BookInstance . objects . all ( ) . count ( ) num_instances_available = BookInstance . objects . filter ( status__exact = 'a' ) . count ( ) num_authors = Author . objects . count ( ) num_genres = Genre . objects . count ( ) num_books_withWord = Book . objects . filter ( title__contains = 'Spire' ) . count ( ) 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_genres' : num_genres , 'num_books_withWord' : num_books_withWord , 'num_visits' : num_visits , } return render ( request , 'index.html' , context = context )
View function for home page of site.
View function for home page of site .
"""View function for home page of site.""" # Generate counts of some of the main objects # Available books (status = 'a') # The 'all()' is implied by default. # Render the HTML template index.html with the data in the context variable
request