Django: Web Development with Python

Book description

From an idea to a prototype – a complete guide for web development with the Django framework

About This Book

  • Explore the best practices to develop applications of a superior quality with Django framework

  • Unravel the common problems of web development in Django

  • This course teaches you major Django functions and will help you improve your skills by developing models, forms, views, and templates

  • Experience the challenges of working on an end-to-end social network project

  • Who This Book Is For

    Web developers who want to use modern Python-based web frameworks like Django to build powerful web applications. The course is mostly self-contained and introduces web development with Python to a reader who is familiar with web development concepts and can help him become an expert in this trade. It’s intended for all levels of web developers, both students and practitioners from novice to experts.

    What You Will Learn

  • Use Django models to store information in the database and generate queries to access a database across models

  • Quickly develop web pages to create, read, update, and delete data from the model using class-based views

  • Generate very maintainable forms with Django

  • Import data from local sources and external web services as well as exporting your data to third parties

  • Deep dive into various aspects of Django from models and views to testing and deployment

  • Familiarize yourself with the various nuances of web development such as browser attacks and databases

  • In Detail

    Data science is hot right now, and the need for multitalented developers is greater than ever before. A basic grounding in building apps with a framework as minimalistic, powerful, and easy-to-learn as Django will be a useful skill to launch your career as an entrepreneur or web developer. Django is a web framework that was designed to strike a balance between rapid web development and high performance. This course will take you on a journey to become an efficient web developer thoroughly understanding the key concepts of Django framework. This learning path is divided into three modules. The course begins with basic concepts of the Django framework. The first module, Django Essentials, is like a practical guide, filled with many real-world examples to build highly effective Django web application. After getting familiar with core concepts of Django, it's time to practice your learning from the first module with the help of over 90 recipes available in this module. In the second module, Web Development with Django Cookbook, you'll learn varying complexities to help you create multilingual, responsive, and scalable websites with Django. By the end of this module, you will have a good understanding of the new features added to Django 1.8 and be an expert at web development processes.The next step is to discover the latest best practices and idioms in this rapidly evolving Django framework. This is what you'll be learning in our third module, Django Design Patterns and Best Practices. This module will teach you common design patterns to develop better Django code. By the end of the module, you will be able to leverage the Django framework to develop a fully functional web application with minimal effort.

    Style and approach

    This course includes all the resources that will help you jump into the web development field with Django and learn how to make scalable and robust web applications. The aim is to create a smooth learning path that will teach you how to get started with the powerful Django framework and perform various web development techniques in depth. Through this comprehensive course, you'll learn web development with Django from scratch to finish!

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of contents

    1. Django: Web Development with Python
      1. Table of Contents
      2. Django: Web Development with Python
      3. Django: Web Development with Python
      4. Credits
      5. Preface
        1. What this learning path covers
        2. What you need for this learning path
        3. Who this learning path is for
        4. Reader feedback
        5. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      6. 1. Module 1
        1. 1. Django's Position on the Web
          1. From Web 1.0 to Web 2.0
            1. Web 1.0
            2. Web 2.0
          2. What is Django?
            1. Django – a web framework
          3. The MVC framework
          4. Why use Django?
          5. Summary
        2. 2. Creating a Django Project
          1. Installing Python 3
            1. Installing Python 3 for Windows
            2. Installing Python 3 for Linux
            3. Installing Python 3 for Mac OS
          2. Installing setuptools
            1. Installing setuptools for Windows
            2. Installing setuptools for Linux
            3. Installing setuptools for Mac OS
          3. Installing PIP
            1. Installing PIP for Windows
            2. Installing PIP for Linux
            3. Installing PIP for Mac OS
          4. Installing Django
            1. Installing Django for Windows
            2. Installing Django for Linux
            3. Installing Django for Mac OS
          5. Starting your project with Django
          6. Creating an application
          7. Configuring the application
          8. Summary
        3. 3. Hello World! with Django
          1. Routing in Django
          2. Regular expressions
            1. The uninterpreted characters
            2. The beginning and the end of the line
            3. The any character regular expression
            4. Character classes
            5. Validating the number of characters
          3. Creating our first URL
          4. Creating our first view
          5. Testing our application
          6. Summary
        4. 4. Working with Templates
          1. Displaying Hello world! in a template
          2. Injecting the data from the view to the template
          3. Creating dynamic templates
          4. Integrating variables in templates
            1. Conditional statements
            2. Looping in a template
          5. Using filters
            1. The upper and lower filters
              1. The lower filter
              2. The upper filter
            2. The capfirst filter
            3. The pluralize filter
            4. The escape and safe to avoid XSS filters
            5. The linebreaks filter
            6. The truncatechars filter
          6. Creating DRY URLs
          7. Extending the templates
          8. Using static files in templates
          9. Summary
        5. 5. Working with Models
          1. Databases and Django
          2. Migrations with South
            1. Installing South
            2. Using the South extension
          3. Creating simple models
            1. The UserProfile model
            2. The Project model
          4. The relationship between the models
            1. Creating the task model with relationships
          5. Extending models
          6. The admin module
            1. Installing the module
            2. Using the module
          7. Advanced usage of models
            1. Using two relationships for the same model
            2. Defining the str method
          8. Summary
        6. 6. Getting a Model's Data with Querysets
          1. The persisting model's data on the database
            1. Filling a model and saving it in the database
          2. Getting data from the database
            1. Getting multiple records
            2. Getting only one record
            3. Getting a model instance from the queryset instance
          3. Using the get parameter
          4. Saving the foreign key
          5. Updating records in the database
            1. Updating a model instance
            2. Updating multiple records
          6. Deleting a record
          7. Getting linked records
          8. Advanced usage of the queryset
            1. Using an OR operator in a queryset
            2. Using the lower and greater than lookups
            3. Performing an exclude query
            4. Making a raw SQL query
          9. Summary
        7. 7. Working with Django Forms
          1. Adding a developer without using Django forms
            1. Template of an HTML form
            2. The view using the POST data reception
          2. Adding a developer with Django forms
            1. CSRF protection
            2. The view with a Django form
            3. Template of a Django form
          3. The form based on a model
            1. The supervisor creation form
          4. Advanced usage of Django forms
            1. Extending the validation form
            2. Customizing the display of errors
            3. Using widgets
            4. Setting initial data in a form
              1. When instantiating the form
              2. When defining fields
          5. Summary
        8. 8. Raising Your Productivity with CBV
          1. The CreateView CBV
            1. An example of minimalist usage
          2. Working with ListView
            1. An example of minimalist usage
            2. Extending ListView
          3. The DetailView CBV
            1. An example of minimalist usage
            2. Extending DetailView
          4. The UpdateView CBV
            1. An example of minimalist usage
            2. Extending the UpdateView CBV
          5. The DeleteView CBV
          6. Going further by extending the CBV
            1. Using a custom class CBV update
          7. Summary
        9. 9. Using Sessions
          1. Creating and getting session variables
            1. An example – showing the last task consulted
          2. About session security
          3. Summary
        10. 10. The Authentication Module
          1. How to use the authentication module
            1. Configuring the Django application
            2. Editing the UserProfile model
          2. Adding a user
          3. Login and logout pages
          4. Restricting access to the connected members
            1. Restricting access to views
            2. Restricting access to URLs
          5. Summary
        11. 11. Using AJAX with Django
          1. Working with jQuery
          2. jQuery basics
            1. CSS selectors in jQuery
            2. Getting back the HTML content
            3. Setting HTML content in an element
            4. Looping elements
            5. Importing the jQuery library
          3. Working with AJAX in the task manager
          4. Summary
        12. 12. Production with Django
          1. Completing the development
          2. Selecting the physical server
          3. Selecting the server software
          4. Selecting the server database
          5. Deploying the Django website
            1. Installing PIP and Python 3
            2. Installing PostgreSQL
            3. Installing virtualenv and creating a virtual environment
          6. Installing Django, South, Gunicorn, and psycopg2
            1. Configuring PostgreSQL
            2. Adaptation of Work_manager to production
            3. Initial South migration
            4. Using Gunicorn
            5. Starting Nginx
          7. Summary
        13. A. Cheatsheet
          1. The field types in models
            1. The numerical field type
            2. The string field type
            3. The temporal field type
            4. Other types of fields
            5. Relationship between models
            6. The model meta attributes
            7. Options common to all fields of models
          2. The form fields
            1. Common options for the form fields
            2. The widget form
            3. Error messages (forms and models)
          3. The template language
            1. Template tags
              1. Loops in dictionaries
              2. Conditional statements
            2. The template filters
            3. The queryset methods
      7. 2. Module 2
        1. 1. Getting Started with Django 1.8
          1. Introduction
          2. Working with a virtual environment
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          3. Creating a project file structure
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          4. Handling project dependencies with pip
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more…
            5. See also
          5. Making your code compatible with both Python 2.7 and Python 3
            1. Getting ready
            2. How to do it…
            3. How it works…
          6. Including external dependencies in your project
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          7. Configuring settings for development, testing, staging, and production environments
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          8. Defining relative paths in the settings
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          9. Creating and including local settings
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          10. Setting up STATIC_URL dynamically for Subversion users
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          11. Setting up STATIC_URL dynamically for Git users
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          12. Setting UTF-8 as the default encoding for MySQL configuration
            1. Getting ready
            2. How to do it…
            3. How it works…
          13. Setting the Subversion ignore property
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          14. Creating the Git ignore file
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          15. Deleting Python-compiled files
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          16. Respecting the import order in Python files
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more…
            5. See also
          17. Creating app configuration
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There is more…
            5. See also
          18. Defining overwritable app settings
            1. Getting ready
            2. How to do it…
            3. How it works…
        2. 2. Database Structure
          1. Introduction
          2. Using model mixins
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more…
            5. See also
          3. Creating a model mixin with URL-related methods
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          4. Creating a model mixin to handle creation and modification dates
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          5. Creating a model mixin to take care of meta tags
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          6. Creating a model mixin to handle generic relations
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          7. Handling multilingual fields
            1. Getting ready
            2. How to do it…
            3. How it works…
          8. Using migrations
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          9. Switching from South migrations to Django migrations
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          10. Changing a foreign key to the many-to-many field
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
        3. 3. Forms and Views
          1. Introduction
          2. Passing HttpRequest to the form
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          3. Utilizing the save method of the form
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          4. Uploading images
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more
            5. See also
          5. Creating a form layout with django-crispy-forms
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more…
            5. See also
          6. Downloading authorized files
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          7. Filtering object lists
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          8. Managing paginated lists
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          9. Composing class-based views
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. There's more…
            5. See also
          10. Generating PDF documents
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          11. Implementing a multilingual search with Haystack
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
        4. 4. Templates and JavaScript
          1. Introduction
          2. Arranging the base.html template
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          3. Including JavaScript settings
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          4. Using HTML5 data attributes
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          5. Opening object details in a modal dialog
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          6. Implementing a continuous scroll
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          7. Implementing the Like widget
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
          8. Uploading images by Ajax
            1. Getting ready
            2. How to do it…
            3. How it works…
            4. See also
        5. 5. Custom Template Filters and Tags
          1. Introduction
          2. Following conventions for your own template filters and tags
            1. How to do it...
          3. Creating a template filter to show how many days have passed since a post was published
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          4. Creating a template filter to extract the first media object
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          5. Creating a template filter to humanize URLs
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          6. Creating a template tag to include a template if it exists
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          7. Creating a template tag to load a QuerySet in a template
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          8. Creating a template tag to parse content as a template
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          9. Creating a template tag to modify request query parameters
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        6. 6. Model Administration
          1. Introduction
          2. Customizing columns on the change list page
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          3. Creating admin actions
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          4. Developing change list filters
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Customizing default admin settings
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          6. Inserting a map into a change form
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        7. 7. Django CMS
          1. Introduction
          2. Creating templates for Django CMS
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          3. Structuring the page menu
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          4. Converting an app to a CMS app
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Attaching your own navigation
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          6. Writing your own CMS plugin
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Adding new fields to the CMS page
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        8. 8. Hierarchical Structures
          1. Introduction
          2. Creating hierarchical categories
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          3. Creating a category administration interface with django-mptt-admin
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          4. Creating a category administration interface with django-mptt-tree-editor
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Rendering categories in a template
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          6. Using a single selection field to choose a category in forms
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Using a checkbox list to choose multiple categories in forms
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        9. 9. Data Import and Export
          1. Introduction
          2. Importing data from a local CSV file
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          3. Importing data from a local Excel file
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          4. Importing data from an external JSON file
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Importing data from an external XML file
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          6. Creating filterable RSS feeds
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Using Tastypie to create API
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          8. Using Django REST framework to create API
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        10. 10. Bells and Whistles
          1. Introduction
          2. Using the Django shell
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          3. Using database query expressions
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          4. Monkey-patching the slugify() function for better internationalization support
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          5. Toggling the Debug Toolbar
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          6. Using ThreadLocalMiddleware
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Caching the method return value
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          8. Using Memcached to cache Django views
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          9. Using signals to notify administrators about new entries
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          10. Checking for missing settings
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
        11. 11. Testing and Deployment
          1. Introduction
          2. Testing pages with Selenium
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          3. Testing views with mock
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          4. Testing API created using Django REST framework
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Releasing a reusable Django app
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          6. Getting detailed error reporting via e-mail
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Deploying on Apache with mod_wsgi
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
          8. Setting up cron jobs for regular tasks
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          9. Creating and using the Fabric deployment script
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
            5. See also
      8. 3. Module 3
        1. 1. Django and Patterns
          1. How does Django work to?
          2. What is a Pattern?
            1. Gang of Four Patterns
            2. Is Django MVC?
            3. Fowler's Patterns
            4. Are there more patterns?
          3. Patterns in this book
            1. Criticism of Patterns
            2. How to use Patterns
          4. Best practices
            1. Python Zen and Django's design philosophy
          5. Summary
        2. 2. Application Design
          1. How to gather requirements
          2. Are you a story teller?
          3. HTML mockups
          4. Designing the application
            1. Dividing a project into Apps
            2. Reuse or roll-your-own?
              1. My app sandbox
            3. Which packages made it?
          5. Before starting the project
          6. SuperBook – your mission, should you choose to accept it
            1. Why Python 3?
            2. Starting the project
          7. Summary
        3. 3. Models
          1. M is bigger than V and C
          2. The model hunt
            1. Splitting models.py into multiple files
          3. Structural patterns
            1. Patterns – normalized models
              1. Problem details
              2. Solution details
                1. Three steps of normalization
                  1. First normal form (1NF)
                  2. Second normal form or 2NF
                  3. Third normal form or 3NF
                  4. Django models
                2. Performance and denormalization
                3. Should we always normalize?
            2. Pattern – model mixins
              1. Problem details
              2. Solution details
                1. Model mixins
            3. Pattern – user profiles
              1. Problem details
              2. Solution details
                1. Signals
                2. Admin
                3. Multiple profile types
            4. Pattern – service objects
              1. Problem details
              2. Solution details
          4. Retrieval patterns
            1. Pattern – property field
              1. Problem details
              2. Solution details
                1. Cached properties
            2. Pattern – custom model managers
              1. Problem details
              2. Solution details
                1. Set operations on QuerySets
                2. Chaining multiple QuerySets
          5. Migrations
          6. Summary
        4. 4. Views and URLs
          1. A view from the top
            1. Views got classier
          2. Class-based generic views
          3. View mixins
            1. Order of mixins
          4. Decorators
          5. View patterns
            1. Pattern – access controlled views
              1. Problem details
              2. Solution details
            2. Pattern – context enhancers
              1. Problem details
              2. Solution details
            3. Pattern – services
              1. Problem details
              2. Solution details
          6. Designing URLs
            1. URL anatomy
              1. What happens in urls.py?
              2. The URL pattern syntax
                1. Mnemonic – parents question pink action-figures
              3. Names and namespaces
              4. Pattern order
              5. URL pattern styles
                1. Departmental store URLs
                2. RESTful URLs
          7. Summary
        5. 5. Templates
          1. Understanding Django's template language features
            1. Variables
            2. Attributes
            3. Filters
            4. Tags
            5. Philosophy – don't invent a programming language
          2. Organizing templates
            1. Support for other template languages
          3. Using Bootstrap
            1. But they all look the same!
          4. Template patterns
            1. Pattern – template inheritance tree
              1. Problem details
              2. Solution details
            2. Pattern – the active link
              1. Problem details
              2. Solution details
                1. A template-only solution
                2. Custom tags
          5. Summary
        6. 6. Admin Interface
          1. Using the admin interface
          2. Enhancing models for the admin
            1. Not everyone should be an admin
          3. Admin interface customizations
            1. Changing the heading
            2. Changing the base and stylesheets
              1. Adding a Rich Text Editor for WYSIWYG editing
            3. Bootstrap-themed admin
            4. Complete overhauls
          4. Protecting the admin
            1. Pattern – feature flags
              1. Problem details
              2. Solution details
          5. Summary
        7. 7. Forms
          1. How forms work
            1. Forms in Django
            2. Why does data need cleaning?
          2. Displaying forms
            1. Time to be crisp
          3. Understanding CSRF
          4. Form processing with Class-based views
          5. Form patterns
            1. Pattern – dynamic form generation
              1. Problem details
              2. Solution details
            2. Pattern – user-based forms
              1. Problem details
              2. Solution details
            3. Pattern – multiple form actions per view
              1. Problem details
              2. Solution details
                1. Separate views for separate actions
                2. Same view for separate actions
            4. Pattern – CRUD views
              1. Problem details
              2. Solution details
          6. Summary
        8. 8. Dealing with Legacy Code
          1. Finding the Django version
            1. Activating the virtual environment
          2. Where are the files? This is not PHP
          3. Starting with urls.py
          4. Jumping around the code
          5. Understanding the code base
            1. Creating the big picture
          6. Incremental change or a full rewrite?
          7. Write tests before making any changes
            1. Step-by-step process to writing tests
          8. Legacy databases
          9. Summary
        9. 9. Testing and Debugging
          1. Why write tests?
          2. Test-driven development
          3. Writing a test case
            1. The assert method
            2. Writing better test cases
          4. Mocking
          5. Pattern – test fixtures and factories
            1. Problem details
            2. Solution details
          6. Learning more about testing
          7. Debugging
            1. Django debug page
              1. A better debug page
          8. The print function
          9. Logging
          10. The Django Debug Toolbar
          11. The Python debugger pdb
          12. Other debuggers
          13. Debugging Django templates
          14. Summary
        10. 10. Security
          1. Cross-site scripting (XSS)
            1. Why are your cookies valuable?
              1. How Django helps
              2. Where Django might not help
            2. Cross-Site Request Forgery (CSRF)
              1. How Django helps
              2. Where Django might not help
            3. SQL injection
              1. How Django helps
              2. Where Django might not help
            4. Clickjacking
              1. How Django helps
            5. Shell injection
              1. How Django helps
            6. And the list goes on
          2. A handy security checklist
          3. Summary
        11. 11. Production-ready
          1. Production environment
            1. Choosing a web stack
            2. Components of a stack
          2. Hosting
            1. Platform as a service
            2. Virtual private servers
            3. Other hosting approaches
          3. Deployment tools
            1. Fabric
              1. Typical deployment steps
            2. Configuration management
          4. Monitoring
          5. Performance
            1. Frontend performance
            2. Backend performance
              1. Templates
              2. Database
              3. Caching
                1. Cached session backend
                2. Caching frameworks
                3. Caching patterns
          6. Summary
        12. A. Python 2 versus Python 3
          1. But I still use Python 2.7!
          2. Python 3
            1. Python 3 for Djangonauts
            2. Change all the __unicode__ methods into __str__
            3. All classes inherit from the object class
            4. Calling super() is easier
            5. Relative imports must be explicit
            6. HttpRequest and HttpResponse have str and bytes types
            7. Exception syntax changes and improvements
            8. Standard library reorganized
            9. New goodies
              1. Using Pyvenv and Pip
            10. Other changes
          3. Further information
      9. A. Bibliography
      10. Index

    Product information

    • Title: Django: Web Development with Python
    • Author(s): Samuel Dauzon, Aidas Bendoraitis, Arun Ravindran
    • Release date: August 2016
    • Publisher(s): Packt Publishing
    • ISBN: 9781787121386