Table Of ContentDjango: Web Development
with Python
From an idea to a prototype – a complete guide
to web development with the Django framework
A course in three modules
BIRMINGHAM - MUMBAI
Django: Web Development with Python
Copyright © 2016 Packt Publishing
All rights reserved. No part of this course may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this course to ensure the accuracy
of the information presented. However, the information contained in this course
is sold without warranty, either express or implied. Neither the authors, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this course.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this course by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
Published on: August 2016
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78712-138-6
www.packtpub.com
Credits
Authors Content Development Editor
Samuel Dauzon Priyanka Mehta
Aidas Bendoraitis
Arun Ravindran Graphics
Disha Haria
Reviewers
Jorge Armin Garcia Lopez Production Coordinator
Aparna Bhagat
Caleb Smith
Deepak Thukral
Patrick Chan
Jake Kronika
Jorge Armin Garcia Lopez
Shoubhik Bose
Kracekumar Ramaraju
Jai Vikram Singh Verma
Preface
Data science is hot right now, and the need for multi-talented developers is greater
than ever before. With a growing skills gap, the need for talented 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
you on a career as an entrepreneur or web developer.
Django is one of the most popular web frameworks in use today. It powers large
websites, such as Pinterest, Instagram, Disqus, and NASA. With a few lines of code,
you can rapidly build a functional and secure website that can scale to millions
of users.
For some years, web development has evolved through frameworks. Web
development has become more efficient and has improved in quality. Django
is a very sophisticated and popular framework. Django is based on the Python
programming language, where the code is clear and easy to read. Also, Django has
a lot of third-party modules that can be used in conjunction with your own apps.
Django has an established and vibrant community, where you can find source code,
get help, and contribute.
This course is a learning path that uses module-by-module pedagogy to help novice
developers learn how to easily deal with the Django framework. This course will also
provide you a basic grounding in the fundamental concepts of web development
with Python, as well as the hands-on experience in order to successfully build web
applications with Django.
[ i ]
Preface
What this learning path covers
Module 1, Django Essentials, a practical guide, filled with many real world examples to
build highly effective Django web application. It begins with step-by-step installation
of Python, PIP, and Django on Windows, Linux, and Mac OS..
Module 2, Web Development with Django Cookbook, covers varying complexities to help
you create multilingual, responsive, and scalable websites with Django.
Module 3, Django Design Patterns and Best Practices, This module will teach you common
design patterns to develop better Django code. Creating a successful web application
involves much more than Django, so advanced topics including REST, testing,
debugging, security, and deployment are also explored in detail in this module.
What you need for this learning path
To develop with Django 1.8, you will need Python 2.7 or Python 3.4, the Pillow
library for image manipulation, the MySQL database and MySQLdb bindings or
PostgreSQL database, virtualenv to keep each project's Python modules separated,
and Git or Subversion for version control.
The other software required for Django development are as follows:
• PIP 1.5
• Text editor (or a Python IDE)
• Web browser (the latest version, please)
For Module 3, Django Design Patterns and Best Practices, it is recommend to work on a
Linux-based system such as Ubuntu or Arch Linux. If you are on Windows, you can
work on a Linux virtual machine using Vagrant or VirtualBox.
Certain chapters might also require installing certain Python libraries or Django
packages. They will be mentioned as, say—the factory_boy package. In most cases,
they can be installed using pip as follows:
$ pip install factory_boy
Hence, it is highly recommended that you first create a separate virtual environment,
as mentioned in Module 3, Chapter 2, Application Design.
[ ii ]
Preface
Who this learning path 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.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this course—what you liked or disliked. Reader feedback is important for us as it
helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail feedback@packtpub.com, and mention
the title of the course in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to any of our product, see our author guide at www.packtpub.com/
authors.
Customer support
Now that you are the proud owner of a Packt course, we have a number of things to
help you to get the most from your purchase.
Downloading the example code
You can download the example code files for this course from your account at
http://www.packtpub.com. If you purchased this course elsewhere, you can
visit http://www.packtpub.com/support and register to have the files e-mailed
directly to you.
You can download the code files by following these steps:
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the course in the Search box.
[ iii ]
Preface
5. Select the course for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.
You can also download the code files by clicking on the Code Files button on the
course's webpage at the Packt Publishing website. This page can be accessed by
entering the course's name in the Search box. Please note that you need to be logged
into your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder
using the latest version of:
• WinRAR / 7-Zip for Windows
• Zipeg / iZip / UnRarX for Mac
• 7-Zip / PeaZip for Linux
The code bundle for the course is also hosted on GitHub at https://github.com/
PacktPublishing/Django-Web-Development-with-Python.We also have other
code bundles from our rich catalog of books and videos available at https://
github.com/PacktPublishing/. Check them out!
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books/courses—maybe a mistake in
the text or the code—we would be grateful if you could report this to us. By doing
so, you can save other readers from frustration and help us improve subsequent
versions of this course. If you find any errata, please report them by visiting http://
www.packtpub.com/submit-errata, selecting your course, clicking on the Errata
Submission Form link, and entering the details of your errata. Once your errata are
verified, your submission will be accepted and the errata will be uploaded to our
website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/
content/support and enter the name of the book in the search field. The required
information will appear under the Errata section.
[ iv ]
Preface
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
Please contact us at copyright@packtpub.com with a link to the suspected pirated
material.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this course, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ v ]