0% found this document useful (0 votes)
72 views

0911 Learning Django

This document provides an overview of Django and examples of using various Django features such as class based views, authentication, databases, deployment, and more.

Uploaded by

Ali Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

0911 Learning Django

This document provides an overview of Django and examples of using various Django features such as class based views, authentication, databases, deployment, and more.

Uploaded by

Ali Mustapha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Django

#django
Table of Contents
About 1

Chapter 1: Getting started with Django 2

Remarks 2

Versions 2

Examples 3

Starting a Project 3

Django Concepts 5

A complete hello world example. 6

Virtual Environment 7

Python 3.3+ 7

Python 2 7

Activate (any version) 7

Alternatively: use virtualenvwrapper 8

Alternatively: use pyenv + pyenv-viritualenv 8

Set your Project Path 9

Single File Hello World Example 9

Deployment friendly Project with Docker support. 10

Project Structure 10

Dockerfile 11

Compose 11

Nginx 12

Usage 12

Chapter 2: Administration 14

Examples 14

Change list 14

Additional CSS styles and JS scripts for admin page 15

Dealing with foreign keys referencing large tables 16

views.py 17

urls.py 17
forms.py 17

admin.py 18

Chapter 3: ArrayField - a PostgreSQL-specific field 19

Syntax 19

Remarks 19

Examples 19

A basic ArrayField 19

Specifying the maximum size of an ArrayField 19

Querying for membership of ArrayField with contains 20

Nesting ArrayFields 20

Querying for all models who contain any item in a list with contained_by 20

Chapter 4: Async Tasks (Celery) 21

Remarks 21

Examples 21

Simple example to add 2 numbers 21

Chapter 5: Authentication Backends 23

Examples 23

Email Authentication Backend 23

Chapter 6: Class based views 24

Remarks 24

Examples 24

Class Based Views 24

views.py 24

urls.py 24

Context data 24

views.py 25

book.html 25

List and Details views 25

app/models.py 25

app/views.py 25

app/templates/app/pokemon_list.html 26
app/templates/app/pokemon_detail.html 26

app/urls.py 26

Form and object creation 27

app/views.py 27

app/templates/app/pokemon_form.html (extract) 27

app/templates/app/pokemon_confirm_delete.html (extract) 28

app/models.py 28

Minimal example 29

Django Class Based Views: Example of CreateView 29

One View, Multiple Forms 30

Chapter 7: Context Processors 32

Remarks 32

Examples 32

Use a context processor to access settings.DEBUG in templates 32

Using a context processor to access your most recent blog entries in all templates 32

Extending your templates 34

Chapter 8: Continuous Integration With Jenkins 35

Examples 35

Jenkins 2.0+ Pipeline Script 35

Jenkins 2.0+ Pipeline Script, Docker Containers 35

Chapter 9: CRUD in Django 37

Examples 37

**Simplest CRUD example** 37

Chapter 10: Custom Managers and Querysets 42

Examples 42

Defining a basic manager using Querysets and `as_manager` method 42

select_related for all queries 43

Define custom managers 43

Chapter 11: Database Routers 45

Examples 45

Adding a Database Routing file 45


Specifying different databases in code 46

Chapter 12: Database Setup 47

Examples 47

MySQL / MariaDB 47

PostgreSQL 48

sqlite 49

Fixtures 49

Django Cassandra Engine 50

Chapter 13: Database transactions 52

Examples 52

Atomic transactions 52

Problem 52

Solution 52

Chapter 14: Debugging 54

Remarks 54

Examples 54

Using Python Debugger (Pdb) 54

Using Django Debug Toolbar 55

Using "assert False" 57

Consider Writing More Documentation, Tests, Logging and Assertions Instead of Using a Debu 57

Chapter 15: Deployment 58

Examples 58

Running Django application with Gunicorn 58

Deploying with Heroku 58

Simple remote deploy fabfile.py 59

Using Heroku Django Starter Template. 60

Django deployment instructions. Nginx + Gunicorn + Supervisor on Linux (Ubuntu) 60

NGINX 61

GUNICORN 62

SUPERVISOR 62

Deploying locally without setting up apache/nginx 63

Chapter 16: Django and Social Networks 64


Click here to download full PDF material

You might also like