The Django Book

Django for Entrepreneurs

James Davis, PhD

Contents

- Preface

- Chapter 1 MVC Framework

- 1.1 Django

- 1.2 Advantages

- 1.3 In Good Company

- 1.4 Conclusion

- Chapter 2 Sprint Zero

- 2.1 Python versions

- 2.2 Installing Python

- 2.2.1 MacOS Installation

- 2.2.2 Windows Installation

- 2.3 Virtual Environments

- 2.4 Install Django

- 2.5 Celebrate

- Chapter 3 Static Pages Application

- 3.1 Project Plan

- 3.2 Getting Started

- 3.3 Create Django Project

- 3.4 Flow

- 3.5 Templates

- 3.6 URL Routing

- 3.7 Views

- 3.8 Tests

- 3.9 Git & GitHub

- 3.10 Celebrate

- Chapter 4 Heroku

- 4.1 Setup account

- 4.2 Heroku CLI

- 4.2.1 MacOS

- 4.2.2 Windows

- 4.2.3 Verify Your Installation

- 4.2.4 Heroku Login

- 4.3 Update Pipfile

- 4.4 Procfile

- 4.5 settings.py

- 4.6 Push to GitHub

- 4.7 Push to Heroku

- Chapter 5 Tweeter (Twitter-ish) App

- 5.1 Project Plan

- 5.2 Getting Started

- 5.3 Databases

- 5.4 CustomUser

- 5.5 User App

- 5.6 Tweets App

- 5.7 Django Admin

- 5.8 Urls / Views / Templates for Tweets

- 5.9 Tests

- 5.10 Heroku

- 5.11 (Optional) Function-based Views

- Chapter 6 Function-based Views

- 6.1 Class-based Views

- 6.2 Function-based Views

- 6.3 Refactor

- 6.4 Options are good

- Chapter 7 Bootstrap

- 7.1 Install

- 7.2 Project Level Templates

- 7.3 Update Tweets Templates

- 7.4 Function-based Views (Optional)

- Chapter 8 User Accounts

- 8.1 Log In / Out

- 8.2 User Registration

- 8.3 DatePicker

- 8.4 Templates

- 8.5 Conclusion

- Chapter 9 Mixins

- 9.1 Must Login to Tweet

- 9.2 Adding Messages

- 9.3 Add Tests

- 9.4 Celebrate

- Chapter 10 Email

- 10.1 SendGrid

- 10.2 Environmental Variables

- 10.3 Git Ignore

- Chapter 11 Django REST Framework

- 11.1 HTTP

- 11.2 REST

- 11.3 Create API App

- 11.4 Install DRF

- 11.5 API Endpoints

- 11.6 Views

- 11.7 Serializers

- 11.8 Browsable API

- 11.9 Conclusion

- Chapter 12 API Permissions

- 12.1 Project-Level Permissions

- 12.2 Custom Permissions

- 12.3 Next Up

- Chapter 13 Token Authentication

- 13.1 Change DRF Default Authentication

- 13.2 Django Rest Auth

- 13.3 Django Allauth

- Chapter 14 Git for Teams

- 14.1 Army of One

- 14.2 GitHub

- 14.3 Assumptions

- 14.4 Add Collaborators

- 14.5 Clone Repository

- 14.6 Collaborating

- 14.7 Branches

- 14.8 Pull Requests

- 14.9 Merging Pull Requests

- Chapter 15 Stripe

- 15.1 Install Stripe

- 15.2 Setup a Stripe account

- 15.3 Payment app

- 15.4 Process a Stripe Payment

- 15.5 Testing

Preface

Admittedly, this book represents my opinion for developing webapps for the startup tech venture.  - Dr.  Davis

This book is intended to give entrepreneurs students a foundational understanding of leveraging a development framework to quickly build a MVP. While there are multiple options, to me, we need a framework that is robust, versatile, popular, and free.  There are other options, such as Rails, that meet these requirements but the rising popularity of Python plus hundreds of readily available packages gives Django an edge above the competition.

A simple search of ‘python popularity’ will return pages of articles, blogs, and information about The Incredible Growth of Python.

Chapter 1

MVC Framework

A framework is a collection of modular tools that abstracts away many of the tasks inherent in the development of an application.  For example, most websites need the same basic functionality: the ability to connect to a database, route traffic, display content on a page, authenticate users, etc.  Rather than recreate all of this from scratch, communities of developers have created frameworks in all the major programming languages

The Model-View-Controller (MVC) is an architectural pattern that separates an application into logical components: the model, the view, and the controller.

The Model defines the data structure and takes to care for querying the database.

The View defines what data should be presented and returns an HTTP response.

The Controller is that part of the application that handles the user interaction.

1.1 Django

Django is a web development framework for Python which offers a standard method for fast and effective website development.  It helps you to assists in building and maintaining quality web applications.  It enables you to make the development process smooth and time-saving.

Django uses a modified version of the MVC architecture called the MVT. The Model-View-Template (MVT) is a different concept compared to MVC. The main difference between these two architectural patterns is that Django itself manages the Controller part (software code that controls the interactions between the Model and View).  The template is an HTML file which mixed with Python and Django template helpers.

1.2 Advantages

Django speeds up your development.  Certain difficult tasks can be accomplished in just a few minutes with the help of Django.  It is free and open source with a robust user base.  It makes the web development process easier and the developer can fully focus on the designing process and boost performance.  Thus, Django becomes an ideal tool for startups, to facilitate development of a product from ideation to deployment.

Django is built using Python, which is a popular and versatile programming language.

- Admin Module

- Secure

- Highly Configurable

- Scalable

- Database Management

1.3 In Good Company

As of 2020, Django has been actively developed for over 15 years, making it a grizzled veteran in software years.  Millions of programmers have already used Django to build their websites, which is undeniably a good thing.  Web development is hard and it does not make sense to repeat the same code, and mistakes, when a large community of developers has already solved these problems for us.

These are a few of the organizations that use the Django framework:

- Disqus

- Instagram

- Spotify

- YouTube

- The Washington Post

- BitBucket

- DropBox

- Eventbrite

- Pinterest

- CheckSeats

1.4 Conclusion

Django is an excellent choice for any developer who wants to build modern, robust web applications.  It is popular, under active development, and thoroughly battle-tested by the largest websites in the world.  In the next chapter you will learn how to configure your computer for Django development.