Complete Django for Production - Creating and launching the tech stack (Part 2/6)
Create a fully-fledged web app with django, redis, postgres, celery and more within only a few minutes. Learn why we use this scaffolding and how to use it to great success.
In this part, we will create and understand the following:
Fully functional and dockerized django application
Separate development and production environments
Additional assisting tools, also dockerized:
Celery for async tasks, with beat and flower
Redis for caching and as message broker
PostgreSQL database
Using code scaffolding to jumpstart the project
I was not the first one to develop a SaaS product. You are neither. Many have been before us and many are to follow. That’s a good thing. We leverage the work and knowledge of others to be better ourselves. Once we have learned enough, we will also give back.
What I’m talking about is code scaffolding or code generation. The base for most SaaS products is the same. What sets you apart is what you do with it.
Getting up and running
I’m sure you have installed all required dependencies while reading part 1, so let’s use them to create our base with cookiecutter-django. Fire up your terminal and paste the following:
cookiecutter https://github.com/cookiecutter/cookiecutter-django
Then, answer the questions like I did here, except for your own and your project’s name and domain (we will buy one later, no worries):
cookiecutter https://github.com/cookiecutter/cookiecutter-django
You've downloaded /Users/dacx/.cookiecutters/cookiecutter-django before. Is it okay to delete and re-download it? [yes]: yes
project_name [My Awesome Project]: Full Cycle Dev
project_slug [full_cycle_dev]:
description [Behold My Awesome Project!]: Full Cycle Dev landing app
author_name [Daniel Roy Greenfeld]: Michael Brayer
domain_name [example.com]: fullcycledev.io
email [michael-brayer@fullcycledev.io]: michael@fullcycledev.io
version [0.1.0]:
Select open_source_license:
1 - MIT
2 - BSD
3 - GPLv3
4 - Apache Software License 2.0
5 - Not open source
Choose from 1, 2, 3, 4, 5 [1]: 1
Select username_type:
1 - username
2 - email
Choose from 1, 2 [1]: 2
timezone [UTC]: Europe/Vienna
windows [n]: n
Select editor:
1 - None
2 - PyCharm
3 - VS Code
Choose from 1, 2, 3 [1]: 1
use_docker [n]: y
Select postgresql_version:
1 - 15
2 - 14
3 - 13
4 - 12
5 - 11
6 - 10
Choose from 1, 2, 3, 4, 5, 6 [1]: 1
Select cloud_provider:
1 - AWS
2 - GCP
3 - Azure
4 - None
Choose from 1, 2, 3, 4 [1]: 1
Select mail_service:
1 - Mailgun
2 - Amazon SES
3 - Mailjet
4 - Mandrill
5 - Postmark
6 - Sendgrid
7 - SendinBlue
8 - SparkPost
9 - Other SMTP
Choose from 1, 2, 3, 4, 5, 6, 7, 8, 9 [1]: 1
use_async [n]: n
use_drf [n]: n
Select frontend_pipeline:
1 - None
2 - Django Compressor
3 - Gulp
4 - Webpack
Choose from 1, 2, 3, 4 [1]: 1
use_celery [n]: y
use_mailpit [n]: y
use_sentry [n]: n
use_whitenoise [n]: y
use_heroku [n]: n
Select ci_tool:
1 - None
2 - Travis
3 - Gitlab
4 - Github
5 - Drone
Choose from 1, 2, 3, 4, 5 [1]: 1
keep_local_envs_in_vcs [y]: y
debug [n]: n
[SUCCESS]: Project initialized, keep up the good work!
Great work, we have now successfully initialized our project. You can find the source code right after code generation on github.
Note: I did not elaborate much on why we answered each question the way we did. That is it’s own topic. Subscribe here for free and join the discord server to not miss it!
We can now start up the application and instantly have the entire tech stack at our hand!
Head back to your terminal, cd into the project folder and execute:
docker compose -f local.yml up
The initial start-up will take a while. Then, your output should look like this:
docker compose -f local.yml up
[+] Running 6/6
django 3.1s
postgres 2.3s
celerybeat 2.1s
flower 2.1s
docs 2.3s
celeryworker 2.3s
[+] Building 15.2s (12/25) docker:desktop-linux
=> [docs internal] load build context 0.0s
=> => transferring context: 3.85kB 0.0s
=> [docs python 1/1] FROM docker.io/library/python:3.11.6-slim-bullseye@sha256:a489c01efef7fe4fb 11.4s
=> => resolve docker.io/library/python:3.11.6-slim-bullseye@sha256:a489c01efef7fe4fb9d7fbd5f8c5e9 0.0s
=> => sha256:a489c01efef7fe4fb9d7fbd5f8c5e9ba3feea100702caa492ed2cc3b7884e4c8 1.65kB / 1.65kB 0.0s
[...]
[+] Running 11/7
✔ Network complete-django-for-production_default Created 0.0s
✔ Volume "complete-django-for-production_full_cycle_dev_local_postgres_data" Created 0.0s
✔ Volume "complete-django-for-production_full_cycle_dev_local_postgres_data_backups" Created 0.0s
✔ Container full_cycle_dev_local_postgres Created 0.1s
✔ Container full_cycle_dev_local_mailpit Created 0.1s
✔ Container full_cycle_dev_local_redis Created 0.1s
✔ Container full_cycle_dev_local_docs Created 0.1s
✔ Container full_cycle_dev_local_django Created 0.1s
✔ Container full_cycle_dev_local_celeryworker Created 0.1s
✔ Container full_cycle_dev_local_celerybeat Created 0.1s
✔ Container full_cycle_dev_local_flower Created 0.1s
Attaching to full_cycle_dev_local_celerybeat, full_cycle_dev_local_celeryworker, full_cycle_dev_local_django,
[...]
full_cycle_dev_local_django | * Running on all addresses (0.0.0.0)
full_cycle_dev_local_django | * Running on http://127.0.0.1:8000
full_cycle_dev_local_django | * Running on http://172.25.0.6:8000
full_cycle_dev_local_django | Press CTRL+C to quit
full_cycle_dev_local_django | * Restarting with watchdog (inotify)
full_cycle_dev_local_celeryworker | [2023-11-06 11:59:51,779: INFO/SpawnProcess-1] mingle: all alone
full_cycle_dev_local_celeryworker | [2023-11-06 11:59:51,787: INFO/SpawnProcess-1] celery@91421ba6a081 ready.
full_cycle_dev_local_django | Performing system checks...
full_cycle_dev_local_django |
full_cycle_dev_local_django | System check identified no issues (0 silenced).
full_cycle_dev_local_django |
full_cycle_dev_local_django | Django version 4.2.7, using settings 'config.settings.local'
full_cycle_dev_local_django | Development server is running at http://0.0.0.0:8000/
full_cycle_dev_local_django | Using the Werkzeug debugger (https://werkzeug.palletsprojects.com/)
full_cycle_dev_local_django | Quit the server with CONTROL-C.
full_cycle_dev_local_django | * Debugger is active!
full_cycle_dev_local_django | * Debugger PIN: 823-814-084
I’ve removed lines to keep it readable. Open http://127.0.0.1:8000/ in your browser to be greeted by the development environment. I will look like this:
If this did not work for you, please contact us on discord and we will help you get up and running.
We have just created the backbone of our product. What would have taken weeks to create and test manually, has been generated instantly. This is overwhelming, but we will manage to understand and use it. In the next post, we will dive deeper into the code and explore what we can do already. Subscribe for free to not miss out!
Like the content? Support!
- Follow on Twitter
- Join the Discord Community