We all know how boring it can be to start the django development server each time. entering the same commands over and over. The good news is that you can write a simple shell script to do so. and after that you just need to run the shell script and yay! your django server is running automatically with just a little command. Cool!!
Let’s say you have a Django project named project and a virtual environment named env inside a directory called project_folder
cd project_folder source env/bin/activate cd project python manage.py runserver
save this script as script.sh or whatever you want.
Run this script using . (dot) rather than ./script.sh
We do this because if we run the script normally with a ./ then the cd command in the script file will get back to the current directory after changing it.
Tip: you probably wanna wanna place this script at your home directory and give a small name like dj.sh or anything so that it’s easier to type in.
But it’s better to make an alias of executing this script and place it at the end in your .bashrc file
alias dj='. $HOME/script.sh'
and now restart the terminal.
From now on, all you need to do is just type dj in the terminal and it will do the job for you!