Auto restart django development server on file save after previous error

I use a simple bash script for this. Here's a one-liner you can use:

$ while true; do python manage.py runserver; sleep 2; done

That will wait 2 seconds before attempting to restart the server. Insert whatever you think is a sane value.

I usually write this as a shell script named runserver.sh, put it in my project root (the same directory with manage.py in it) and add it to the gitignore.

while true; do
  echo "Re-starting Django runserver"
  python manage.py runserver
  sleep 2
done

If you do this, remember to chmod +x runserver.sh, then you can execute it with:

./runserver.sh

Use Ctrl-c Ctrl-c to exit.

Tags:

Python

Django