Feb 10, 2023 · Updated: Feb 22, 2023 · by Tim Kamanin
As a Django developer, I have to run multiple processes while developing, such as the Django server, a JavaScript compiler, and Celery. Launching these processes separately can be time-consuming and tedious. Just try opening three terminal windows, and you'll understand what I mean.
Finally, I found a solution in the Rails community. In Rails, when they do development, they launch a single bin/dev
bash file, which takes care of the rest: it launches a dev server, an asset pipeline, a queue worker, and so on.
Hey, why can't we do the same in Django?!
Actually, we can! Thus, I adopted the approach for Django and want to share it with you.
Create a bin/dev
bash file in your project's root directory. We use a bash script in this file to run multiple processes simultaneously.
#!/usr/bin/env bash
if ! command -v honcho &> /dev/null
then
echo "Installing honcho…"
pip install honcho
fi
honcho start -f Procfile.dev
In this file, we install and run a Python package called Hocho, a tool for managing Procfile-based applications.
Once you have created the bin/dev
file, set its permissions by running the following command:
chmod +x ./bin/dev
For Honcho, we need a Procfile
, a file in which you can declare multiple processes, or terminal commands, to launch and run simultaneously. It is exactly what we need: to run the server, Webpack, Celery, all at once.
Let\'s create a Procfile.dev
file in the root directory of your project. In this file, specify the commands for each process that you want to run:
django: python manage.py runserver
js: webpack -w
css: python manage.py tailwind start
celery: celery
In this example, the Procfile.dev
launches the Django dev server, Webpack, Tailwind CSS compiler, and Celery worker all at once.
To launch all the processes, run the following command in your terminal:
./bin/dev
And that's it! Watch the screen and enjoy the flow of command logs. You're Thomas Anderson!
Give it a try and see how it can improve your workflow.
Hey, if you've found this useful, please share the post to help other folks find it: