Web Development with Django Cookbook - Second Edition

Over 90 practical recipes to help you create scalable websites using the Django 1.8 framework

Web Development with Django Cookbook - Second Edition

This ebook is included in a Mapt subscription
Aidas Bendoraitis

2 customer reviews
Over 90 practical recipes to help you create scalable websites using the Django 1.8 framework
$0.00
$39.99
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781785886775
Paperback384 pages

Book Description

Django is a web framework that was designed to strike a balance between rapid web development and high performance. It has the capacity to handle applications with high levels of user traffic and interaction, and can integrate with massive databases on the backend, constantly collecting and processing data in real time.

Through this book, you'll discover that collecting data from different sources and providing it to others in different formats isn't as difficult as you thought. It follows a task-based approach to guide you through all the web development processes using the Django framework. We’ll start by setting up the virtual environment for a Django project and configuring it. Then you’ll learn to write reusable pieces of code for your models and find out how to manage database schema changes using South migrations. After that, we’ll take you through working with forms and views to enter and list data. With practical examples on using templates and JavaScript together, you will discover how to create the best user experience. In the final chapters, you'll be introduced to some programming and debugging tricks and finally, you will be shown how to test and deploy the project to a remote dedicated server.

By the end of this book, you will have a good understanding of the new features added to Django 1.8 and be an expert at web development processes.

Table of Contents

Chapter 1: Getting Started with Django 1.8
Introduction
Working with a virtual environment
Creating a project file structure
Handling project dependencies with pip
Making your code compatible with both Python 2.7 and Python 3
Including external dependencies in your project
Configuring settings for development, testing, staging, and production environments
Defining relative paths in the settings
Creating and including local settings
Setting up STATIC_URL dynamically for Subversion users
Setting up STATIC_URL dynamically for Git users
Setting UTF-8 as the default encoding for MySQL configuration
Setting the Subversion ignore property
Creating the Git ignore file
Deleting Python-compiled files
Respecting the import order in Python files
Creating app configuration
Defining overwritable app settings
Chapter 2: Database Structure
Introduction
Using model mixins
Creating a model mixin with URL-related methods
Creating a model mixin to handle creation and modification dates
Creating a model mixin to take care of meta tags
Creating a model mixin to handle generic relations
Handling multilingual fields
Using migrations
Switching from South migrations to Django migrations
Changing a foreign key to the many-to-many field
Chapter 3: Forms and Views
Introduction
Passing HttpRequest to the form
Utilizing the save method of the form
Uploading images
Creating a form layout with django-crispy-forms
Downloading authorized files
Filtering object lists
Managing paginated lists
Composing class-based views
Generating PDF documents
Implementing a multilingual search with Haystack
Chapter 4: Templates and JavaScript
Introduction
Arranging the base.html template
Including JavaScript settings
Using HTML5 data attributes
Opening object details in a modal dialog
Implementing a continuous scroll
Implementing the Like widget
Uploading images by Ajax
Chapter 5: Custom Template Filters and Tags
Introduction
Following conventions for your own template filters and tags
Creating a template filter to show how many days have passed since a post was published
Creating a template filter to extract the first media object
Creating a template filter to humanize URLs
Creating a template tag to include a template if it exists
Creating a template tag to load a QuerySet in a template
Creating a template tag to parse content as a template
Creating a template tag to modify request query parameters
Chapter 6: Model Administration
Introduction
Customizing columns on the change list page
Creating admin actions
Developing change list filters
Customizing default admin settings
Inserting a map into a change form
Chapter 7: Django CMS
Introduction
Creating templates for Django CMS
Structuring the page menu
Converting an app to a CMS app
Attaching your own navigation
Writing your own CMS plugin
Adding new fields to the CMS page
Chapter 8: Hierarchical Structures
Introduction
Creating hierarchical categories
Creating a category administration interface with django-mptt-admin
Creating a category administration interface with django-mptt-tree-editor
Rendering categories in a template
Using a single selection field to choose a category in forms
Using a checkbox list to choose multiple categories in forms
Chapter 9: Data Import and Export
Introduction
Importing data from a local CSV file
Importing data from a local Excel file
Importing data from an external JSON file
Importing data from an external XML file
Creating filterable RSS feeds
Using Tastypie to create API
Using Django REST framework to create API
Chapter 10: Bells and Whistles
Introduction
Using the Django shell
Using database query expressions
Monkey-patching the slugify() function for better internationalization support
Toggling the Debug Toolbar
Using ThreadLocalMiddleware
Caching the method return value
Using Memcached to cache Django views
Using signals to notify administrators about new entries
Checking for missing settings
Chapter 11: Testing and Deployment
Introduction
Testing pages with Selenium
Testing views with mock
Testing API created using Django REST framework
Releasing a reusable Django app
Getting detailed error reporting via e-mail
Deploying on Apache with mod_wsgi
Setting up cron jobs for regular tasks
Creating and using the Fabric deployment script

What You Will Learn

  • Get started with the basic configuration necessary to start any Django project
  • Build a database structure out of reusable model mixins
  • Manage forms and views and get to know some useful patterns that are used to create them
  • Create handy template filters and tags that you can reuse in every project
  • Integrate your own functionality into the Django CMS
  • Manage hierarchical structures with MPTT
  • Import data from local sources and external web services as well as exporting your data to third parties
  • Implement a multilingual search with Haystack
  • Test and deploy your project efficiently

Authors

Table of Contents

Chapter 1: Getting Started with Django 1.8
Introduction
Working with a virtual environment
Creating a project file structure
Handling project dependencies with pip
Making your code compatible with both Python 2.7 and Python 3
Including external dependencies in your project
Configuring settings for development, testing, staging, and production environments
Defining relative paths in the settings
Creating and including local settings
Setting up STATIC_URL dynamically for Subversion users
Setting up STATIC_URL dynamically for Git users
Setting UTF-8 as the default encoding for MySQL configuration
Setting the Subversion ignore property
Creating the Git ignore file
Deleting Python-compiled files
Respecting the import order in Python files
Creating app configuration
Defining overwritable app settings
Chapter 2: Database Structure
Introduction
Using model mixins
Creating a model mixin with URL-related methods
Creating a model mixin to handle creation and modification dates
Creating a model mixin to take care of meta tags
Creating a model mixin to handle generic relations
Handling multilingual fields
Using migrations
Switching from South migrations to Django migrations
Changing a foreign key to the many-to-many field
Chapter 3: Forms and Views
Introduction
Passing HttpRequest to the form
Utilizing the save method of the form
Uploading images
Creating a form layout with django-crispy-forms
Downloading authorized files
Filtering object lists
Managing paginated lists
Composing class-based views
Generating PDF documents
Implementing a multilingual search with Haystack
Chapter 4: Templates and JavaScript
Introduction
Arranging the base.html template
Including JavaScript settings
Using HTML5 data attributes
Opening object details in a modal dialog
Implementing a continuous scroll
Implementing the Like widget
Uploading images by Ajax
Chapter 5: Custom Template Filters and Tags
Introduction
Following conventions for your own template filters and tags
Creating a template filter to show how many days have passed since a post was published
Creating a template filter to extract the first media object
Creating a template filter to humanize URLs
Creating a template tag to include a template if it exists
Creating a template tag to load a QuerySet in a template
Creating a template tag to parse content as a template
Creating a template tag to modify request query parameters
Chapter 6: Model Administration
Introduction
Customizing columns on the change list page
Creating admin actions
Developing change list filters
Customizing default admin settings
Inserting a map into a change form
Chapter 7: Django CMS
Introduction
Creating templates for Django CMS
Structuring the page menu
Converting an app to a CMS app
Attaching your own navigation
Writing your own CMS plugin
Adding new fields to the CMS page
Chapter 8: Hierarchical Structures
Introduction
Creating hierarchical categories
Creating a category administration interface with django-mptt-admin
Creating a category administration interface with django-mptt-tree-editor
Rendering categories in a template
Using a single selection field to choose a category in forms
Using a checkbox list to choose multiple categories in forms
Chapter 9: Data Import and Export
Introduction
Importing data from a local CSV file
Importing data from a local Excel file
Importing data from an external JSON file
Importing data from an external XML file
Creating filterable RSS feeds
Using Tastypie to create API
Using Django REST framework to create API
Chapter 10: Bells and Whistles
Introduction
Using the Django shell
Using database query expressions
Monkey-patching the slugify() function for better internationalization support
Toggling the Debug Toolbar
Using ThreadLocalMiddleware
Caching the method return value
Using Memcached to cache Django views
Using signals to notify administrators about new entries
Checking for missing settings
Chapter 11: Testing and Deployment
Introduction
Testing pages with Selenium
Testing views with mock
Testing API created using Django REST framework
Releasing a reusable Django app
Getting detailed error reporting via e-mail
Deploying on Apache with mod_wsgi
Setting up cron jobs for regular tasks
Creating and using the Fabric deployment script

Book Details

ISBN 139781785886775
Paperback384 pages
Read More
From 2 reviews

Read More Reviews