Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Generic Views


While working with Django, you will notice that there are certain types of views that are always needed regardless of the project that you are working on. For this reason, Django comes with a set of views that can be used in any project. These views are called generic views and we actually used one of them in a previous chapter. Remember the direct_to_template view that renders a template into a page? This view is one example of generic views.

Django offers generic views for the following purposes:

  • Creating simple views for tasks such as redirecting to another URL or rendering a template.

  • Listing and detail views for displaying objects from a data model. These views are similar to how the admin page displays listing and detail pages for data models.

  • Views to generate date-based archive pages. These can be particularly useful for blogs.

  • Views for creating, editing and deleting objects in data models.

To use one of these views, you import it from django.views.generic and then map the...