Book Image

Django 2 Web Development Cookbook - Third Edition

By : Jake Kronika, Aidas Bendoraitis
Book Image

Django 2 Web Development Cookbook - Third Edition

By: Jake Kronika, Aidas Bendoraitis

Overview of this book

Django is a framework designed to balance rapid web development with high performance. It handles high levels of user traffic and interaction, integrates with a variety of databases, and collects and processes data in real time. This book follows a task-based approach to guide you through developing with the Django 2.1 framework, starting with setting up and configuring Docker containers and a virtual environment for your project. You'll learn how to write reusable pieces of code for your models and manage database changes. You'll work with forms and views to enter and list data, applying practical examples using templates and JavaScript together for the optimum user experience. This cookbook helps you to adjust the built-in Django administration to fit your needs and sharpen security and performance to make your web applications as robust, scalable, and dependable as possible. You'll also explore integration with Django CMS, the popular content management suite. In the final chapters, you'll learn programming and debugging tricks and discover how collecting data from different sources and providing it to others in various formats can be a breeze. By the end of the book, you'll learn how to test and deploy projects to a remote dedicated server and scale your application to meet user demands.
Table of Contents (14 chapters)

Introduction

As you know, Django has an extensive template system with features such as template inheritance, filters to change the representation of values, and tags for presentational logic. Moreover, Django allows you to add your own template filters and tags to your apps. Custom filters or tags should be located in a template tag library file under the templatetags Python package in your app. Then, your template tag library can be loaded in any template with the {% load %} template tag. In this chapter, we will create several useful filters and tags that will give more control to template editors.

To see the template tags of this chapter in action, create either a virtual environment or a Docker project, extract the code provided for this chapter there, run the development server, and visit the appropriate URL for the development site in a browser. With a virtual environment...