From an idea to a prototype - a complete guide for web development with the Django frameworkAbout 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 projectWho This Book Is ForWeb 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 databasesIn DetailData 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 approachThis 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!
Author(s): Samuel Dauzon; Samuel Dauzon; Aidas Bendoraitis; Arun Ravindran; Aidas Bendoraitis; Arun Ravindran
Year: 2016
Language: English
Pages: 717
Cover
Copyright
Credits
Preface
Table of Content
Module 1
Chapter 1: Django's Position on the Web
From Web 1.0 to Web 2.0
What is Django?
The MVC framework
Why use Django?
Summary
Chapter 2: Creating a Django Project
Installing Python 3
Installing setuptools
Installing PIP
Installing Django
Starting your project with Django
Creating an application
Configuring the application
Summary
Chapter 3: Hello World! with Django
Routing in Django
Regular expressions
Creating our first URL
Creating our first view
Testing our application
Summary
Chapter 4: Working with Templates
Displaying Hello world! in a template
Injecting the data from the view to the template
Creating dynamic templates
Integrating variables in templates
Using filters
Creating DRY URLs
Extending the templates
Using static files in templates
Summary
Chapter 5: Working with Models
Databases and Django
Migrations with South
Creating simple models
The relationship between the models
Extending models
The admin module
Advanced usage of models
Summary
Chapter 6: Getting a Model's Data
with Querysets
The persisting model's data on the database
Getting data from the database
Using the get parameter
Saving the foreign key
Updating records in the database
Deleting a record
Getting linked records
Advanced usage of the queryset
Summary
Chapter 7: Working with Django Forms
Adding a developer without using Django forms
Adding a developer with Django forms
The form based on a model
Advanced usage of Django forms
Summary
Chapter 8: Raising Your Productivity
with CBV
The CreateView CBV
Working with ListView
The DetailView CBV
The UpdateView CBV
The DeleteView CBV
Going further by extending the CBV
Summary
Chapter 9: Using Sessions
Creating and getting session variables
About session security
Summary
Chapter 10: The Authentication Module
How to use the authentication module
Adding a user
Login and logout pages
Restricting access to the connected members
Summary
Chapter 11: Using AJAX with Django
Working with jQuery
jQuery basics
Working with AJAX in the task manager
Summary
Chapter 12: Production with Django
Completing the development
Selecting the physical server
Selecting the server software
Selecting the server database
Deploying the Django website
Installing Django, South, Gunicorn, and psycopg2
Summary
Cheatsheet
The field types in models
The form fields
The template language
Module 2
Chapter 1: Getting Started with Django 1.8
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
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
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
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
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
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
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
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
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
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
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
Module 3
Chapter 1: Django and Patterns
How does Django work to?
What is a Pattern?
Patterns in this book
Best practices
Summary
Chapter 2: Application Design
How to gather requirements
Are you a story teller?
HTML mockups
Designing the application
Before starting the project
SuperBook – your mission, should you choose to accept it
Summary
Chapter 3: Models
M is bigger than V and C
The model hunt
Structural patterns
Retrieval patterns
Migrations
Summary
Chapter 4: Views and URLs
A view from the top
Class-based generic views
View mixins
Decorators
View patterns
Designing URLs
Summary
Chapter 5: Templates
Understanding Django's template language features
Organizing templates
Using Bootstrap
Template patterns
Summary
Chapter 6: Admin Interface
Enhancing models for the admin
Admin interface customizations
Protecting the admin
Summary
Chapter 7: Forms
How forms work
Displaying forms
Understanding CSRF
Form processing with Class-based views
Form patterns
Summary
Chapter 8: Dealing with Legacy Code
Finding the Django version
Where are the files? This is not PHP
Starting with urls.py
Jumping around the code
Understanding the code base
Incremental change or a full rewrite?
Write tests before making any changes
Legacy databases
Summary
Chapter 9: Testing and Debugging
Why write tests?
Test-driven development
Writing a test case
Mocking
Pattern – test fixtures and factories
Learning more about testing
Debugging
The print function
Logging
The Django Debug Toolbar
The Python debugger pdb
Other debuggers
Debugging Django templates
Summary
Chapter 10: Security
Cross-site scripting (XSS)
A handy security checklist
Summary
Chapter 11: Production-ready
Production environment
Hosting
Deployment tools
Monitoring
Performance
Summary
Appendix: Python 2 versus Python 3
But I still use Python 2.7!
Python 3
Further information
Bibliography