Book Image

Mastering Django: Core

By : Nigel George
Book Image

Mastering Django: Core

By: Nigel George

Overview of this book

Mastering Django: Core is a completely revised and updated version of the original Django Book, written by Adrian Holovaty and Jacob Kaplan-Moss - the creators of Django. The main goal of this book is to make you a Django expert. By reading this book, you’ll learn the skills needed to develop powerful websites quickly, with code that is clean and easy to maintain. This book is also a programmer’s manual that provides complete coverage of the current Long Term Support (LTS) version of Django. For developers creating applications for commercial and business critical deployments, Mastering Django: Core provides a complete, up-to-date resource for Django 1.8LTS with a stable code-base, security fixes and support out to 2018.
Table of Contents (33 chapters)
Mastering Django: Core
Credits
About the Author
www.PacktPub.com
Preface
Free Chapter
1
Introduction to Django and Getting Started

Common arguments to generic views


Most of these views take a large number of arguments that can change the generic view's behavior. Many of these arguments work the same across multiple views. Table C.1 describes each of these common arguments; anytime you see one of these arguments in a generic view's argument list, it will work as described in the table.

Argument

Description

allow_empty

A Boolean specifying whether to display the page if no objects are available. If this is False and no objects are available, the view will raise a 404 error instead of displaying an empty page. By default, this is True.

context_processors

A list of additional template-context processors (besides the defaults) to apply to the view's template. See Chapter 9, Advanced Models, for information on template context processors.

extra_context

A dictionary of values to add to the template context. By default, this is an empty dictionary. If a value in the dictionary is callable, the generic view will call it just before rendering the template.

mimetype

The MIME type to use for the resulting document. It defaults to the value of the DEFAULT_MIME_TYPE setting, which is text/html if you haven't changed it.

queryset

A QuerySet (that is, something like Author.objects.all()) to read objects from. See Appendix B for more information about QuerySet objects. Most generic views require this argument.

template_loader

The template loader to use when loading the template. By default, it's django.template.loader. See Chapter 9, Advanced Models, for information on template loaders.

template_name

The full name of a template to use in rendering the page. This lets you override the default template name derived from the QuerySet.

template_object_name

The name of the template variable to use in the template context. By default, this is 'object'. Views that list more than one object (that is, object_list views and various objects-for-date views) will append '_list' to the value of this parameter.

Table C.1: Common Generic View Arguments