Django Development Server with DEBUG=False

When you run the Django development server with DEBUG=True, static files are served from their location before collectstatic is run. This is what you want because changes you make are immediately reflected in your pages. Also all hosts are allowed.

Of course you would never run in production with DEBUG=True. This means your development system is not a very good replica of the production system when it comes to static files. If you are having problems with static files, it would be nice if you could work on them in development. It turns out you can. Just run:

python runserver --insecure

You also will need to setup a local directory for collectstatic to write to:

MEDIA_ROOT = 'my local media root'
STATIC_ROOT = 'my local static root'

then run collectstatic. In my case, I also needed to turn off django-pipeline.

Django Development with Vagrant and Ansible

My basic workflow is to use Vagrant and Ansible to configure a local virtual machine, then use Ansible to configure the production server. The goal is to have the local and production servers be nearly identical.

The both machines serve Django using nginx and gunicorn. I use a Vagrant synced folder to allow me to edit the code during development. I have an terminal with an SSH connection to the Vagrant machine that I use to restart the server when the code changes. This works, but the edit/run cycle is slow compared to the good old days of using the Django development server. How can I get back to using the development server?

One option would be to go back to the old days and install a local virtualenv and database. This seems clumsy to me. The better option is to open an IP address on my local virtual machine and then run Django development machine on that port on the VM. Here are the steps.

1) SSH into the local server and start the virtualenv.

2) Stop nginx:

service nginx stop

3) Run the Django development server on the Vagrant IP address:

python runserver --settings=myapp.settings.local