Subclassing Django’s runserver causes command to be run twice
This week I was creating my own version of the Django management command runserver
. Like the built-in, I wanted to run a lightweight development only web server for my Django app. In addition, I was looking to run a syncdb, load some initial data and start up the server with that. The goal was to use an in-memory sqlite3 database, and use this command as a way to spin up an interactive test instance.
This is easily achieved by using call_command
to call syncdb
and runserver
in sequence. The in-memory sqlite3 config I would leave to a Django settings file. But I noticed that syncdb
seemed to be getting called twice, leading to double the start up time.
Rooting around in the Django bug database, I found that this was a known issue with the default auto-reloading functionality of runserver
. The solution turned out to be a simple as disabling that functionality by passing an option to the native runserver
when you use call_command
.