Book description
Create your own websites easily, securely, and quickly with Django by tackling practical activities based on realistic case studies
Key Features
- Understand Django functionality and the Model-View-Template (MVT) paradigm
- Create and iteratively build a book review website, adding features as you build your knowledge
- Explore advanced concepts such as REST API implementation and third-party module integration
Book Description
Do you want to develop reliable and secure applications that stand out from the crowd without spending hours on boilerplate code? You’ve made the right choice trusting the Django framework, and this book will tell you why. Often referred to as a “batteries included” web development framework, Django comes with all the core features needed to build a standalone application. Web Development with Django will take you through all the essential concepts and help you explore its power to build real-world applications using Python.
Throughout the book, you’ll get the grips with the major features of Django by building a website called Bookr – a repository for book reviews. This end-to-end case study is split into a series of bitesize projects presented as exercises and activities, allowing you to challenge yourself in an enjoyable and attainable way. As you advance, you'll acquire various practical skills, including how to serve static files to add CSS, JavaScript, and images to your application, how to implement forms to accept user input, and how to manage sessions to ensure a reliable user experience. You’ll cover everyday tasks that are part of the development cycle of a real-world web application.
By the end of this Django book, you'll have the skills and confidence to creatively develop and deploy your own projects.
What you will learn
- Create a new application and add models to describe your data
- Use views and templates to control behavior and appearance
- Implement access control through authentication and permissions
- Develop practical web forms to add features such as file uploads
- Build a RESTful API and JavaScript code that communicates with it
- Connect to a database such as PostgreSQL
Who this book is for
This book is for programmers looking to enhance their web development skills using the Django framework. To fully understand the concepts explained in this book, basic knowledge of Python programming as well as familiarity with JavaScript, HTML, and CSS is assumed.
Table of contents
- Web Development with Django
- Contributors
- About the authors
- About the reviewer
- Preface
-
Chapter 1: An Introduction to Django
- Technical requirements
- Scaffolding a Django project and app
- Understanding the model-view-template paradigm
- Exploring the Django project structure
- Introducing Django views
- Exploring URL mapping detail
- Working with GET, POST, and QueryDict objects
- Exploring Django settings
- Finding HTML templates in app directories
- Debugging and dealing with errors
- Activity 1.01 – creating a site welcome screen
- Activity 1.02 – a book search scaffold
- Summary
-
Chapter 2: Models and Migrations
- Technical requirements
- Understanding and using databases
- Understanding CRUD operations using SQL
- Exploring Django ORM
- Creating Django models and migrations
-
Django’s database CRUD operations
- Exercise 2.02 – creating an entry in the bookr database
- Exercise 2.03 – using the create() method to create an entry
- Creating an object with a foreign key
- Exercise 2.04 – creating records for a many-to-one relationship
- Exercise 2.05 – creating records with many-to-many relationships
- Exercise 2.06 – a many-to-many relationship using the add() method
- Using the create() and set() methods for many-to-many relationships
- Read operations
- Exercise 2.07 – using the get() method to retrieve an object
- Returning an object using the get() method
- Exercise 2.08 – using the all() method to retrieve a set of objects
- Retrieving objects by filtering
- Exercise 2.09 – using the filter() method to retrieve objects
- Filtering by field lookups
- Using pattern matching for filtering operations
- Retrieving objects by using the exclude() method
- Retrieving objects using the order_by() method
- Querying across relationships
- Querying using foreign keys
- Querying using the model name
- Querying across foreign key relationships using the object instance
- Exercise 2.10 – querying across a many-to-many relationship using the field lookup
- Exercise 2.11 – a many-to-many query using objects
- Exercise 2.12 – a many-to-many query using the set() method
- Exercise 2.13 – using the update() method
- Exercise 2.14 – using the delete() method
- Bulk create and bulk update operations
- Performing complex lookups using Q objects
- Activity 2.01 – creating models for a project management application
- Populating the Bookr project’s database
- Summary
-
Chapter 3: URL Mapping, Views, and Templates
- Technical requirements
- Understanding function-based views
- Understanding class-based views
- URL configuration
-
Working with Django templates
- Exercise 3.02 – using templates to display a greeting message
- Django’s template language
- Exercise 3.03 – displaying a list of books and reviews
- Template inheritance
- Template styling with Bootstrap
- Exercise 3.04 – adding template inheritance and a Bootstrap navigation bar
- Activity 3.01 – implementing the book details view
- Summary
- Chapter 4: An Introduction to Django Admin
-
Chapter 5: Serving Static Files
- Technical requirements
- Static file serving
- Introduction to Static Files Finder
- Generating static URLs with the static template tag
- FileSystemFinder
- Static file finders – use during collectstatic
- STATICFILES_DIRS prefixed mode
- The findstatic command
- Serving the latest files (for cache invalidation)
- Custom storage engines
- Summary
- Chapter 6: Forms
- Chapter 7: Advanced Form Validation and Model Forms
-
Chapter 8: Media Serving and File Uploads
- Technical requirements
- Settings for media uploads and serving
- File uploads using HTML forms
- File uploads with Django forms
- Image uploads with Django forms
- Serving uploaded (and other) files using Django
- ModelForms and file uploads
- Activity 8.01 – image and PDF upload of books
- Activity 8.02 – displaying the cover and sample link
- Summary
- Chapter 9: Sessions and Authentication
-
Chapter 10: Advanced Django Admin and Customizations
- Technical requirements
-
Customizing the admin site
- Discovering admin files in Django
- Django’s AdminSite class
- Exercise 10.01 – creating a custom admin site for Bookr
- Overriding the default admin.site
- Exercise 10.02 – overriding the default admin site
- Customizing admin site text using AdminSite attributes
- Customizing admin site templates
- Exercise 10.03 – customizing the logout template for the Bookr admin site
-
Adding views to the admin site
- Creating the view function
- Accessing common template variables
- Mapping URLs for the custom view
- Restricting custom views to the admin site
- Exercise 10.04 – adding custom views to the admin site
- Passing additional keys to templates using template variables
- Activity 10.01 – building a custom admin dashboard with a built-in search
- Summary
- Chapter 11: Advanced Templating and Class-Based Views
- Chapter 12: Building a REST API
- Chapter 13: Generating CSV, PDF, and Other Binary Files
- Chapter 14: Testing Your Django Applications
- Chapter 15: Django Third-Party Libraries
- Chapter 16: Using a Frontend JavaScript Library with Django
- Index
- Other Books You May Enjoy
Product information
- Title: Web Development with Django - Second Edition
- Author(s):
- Release date: May 2023
- Publisher(s): Packt Publishing
- ISBN: 9781803230603
You might also like
video
Django 3 - Full Stack Websites with Python Web Development
Django is an amazing framework for web developers because it provides the infrastructure required for database-driven …
video
Modern JavaScript from the Beginning - Second Edition
This course is a comprehensive introduction to JavaScript, covering everything from the basics of variables, data …
book
Test-Driven Development with Python, 3rd Edition
The third edition of this trusted guide demonstrates the practical advantages of test-driven development (TDD) with …
book
Django 5 By Example - Fifth Edition
Build four real-world Django apps and learn Django by doing. Create fully functional web applications with …