This repository contains the code for the third class in Andrew Pinkham ’s Python Web Development series, titled Advanced Web Development in Python with Django . The series is published by Pearson and may be bought on InformIT or viewed on Safari Books Online . The series is for intermediate programmers new to web development or Django.
Andrew may be reached at JamBon Software for consulting and training.
The asynchronous code has been upgraded to work with Starlette 0.13 and now works with ASGI 3.0
NB: The extra code for resizing images using Celery (mentioned in Lesson 6) will be added in March 2020.
Python 3.6+ (with SQLite3 support)
a virtual environment (e.g.:
`venv< https://docs.python.org/3/library/venv.html >`__,
`virtualenvwrapper< https://virtualenvwrapper.readthedocs.io/en/latest/install.html >`__)
All other technical requirements are installed by
requirement files included in the repository. This includes
For a full guide to using this code please refer to Lesson 2 of the second class. The lesson demonstrates how to get started locally as well as how to use the Docker setup.
If you are unable to run Docker on your machine skip to the Local Setup section.
Docker Setup ¶
The use of Docker images allows us to avoid installing all of our dependencies—including PostgeSQL—locally. Furthermore, as discussed in second class, it helps with parity between our development and production environments.
Our Docker containers expect the existence of an environment file. To
generate it on *nix systems please invoke the
On Windows please invoke the batch file.
If you run into problems please refer to the videos for why we use this and what is needed in the event these scripts do not work.
To run the Docker containers use the command below.
If you wish to run the servers in the background use the
etached) flag, as demonstrated below.
docker-compose up -d
To turn off the server use Control-C in the terminal window. If running in the background use the command below.
To remove all of the assets created by Docker to run the server use the command below.
docker-compose down --volumes --rmi local
flag may be shortened to
Local Setup ¶
to install your development dependencies.
$ python3 -m pip install -r requirements/development.txt
If you have checked out to an earlier part of the code note that you
will need to use
You will need to define the
environment variable. If you
would like to use PostgreSQL locally you will need to set
export SECRET_KEY=`head -c 75 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 50` # replace the variables in <> below export DATABASE_URL='postgres://<USER>:<PASSWORD>@<SERVER>:5432/<DB_NAME>'
To make perusing the code in this repository as simple as possible the
project defines its own
file with custom commands
To enable the commands you must first point your local git configuration at the file provided. Either of the two commands below should work.
# relative path git config --local include.path "../.gitconfig" # absolute path - *nix only! git config --local include.path "`builtin pwd`/.gitconfig"
This will enable the following git commands:
git next: Move to the next example/commit
git prev: Move to the previous example/commit
git ci: shortcut for
git co: shortcut for
git st: shortcut for
git ll: shortcut for
git log --oneline
These commands can be used on any of the branches in this repository.