PyCharm on a Django app with Vagrant

I work for Mozilla, and we’re working on an internal tool to help us manage our repository (tree) tests.  We use a Vagrant environment to run the service (back-end) portion and the front-end is written in Angular.js.  The project is called Treeherder.

I love using PyCharm, and love the debugger, and wanted to debug some code on the service.  I ran into a few hiccups with it, but now have it working.  Here’s how I did it.

Firstly, credit where credit is due:

After those things, my configuration looked like this:

Screenshot 2014-09-04 11.54.24

and my environment variables (which were a bit of a pain to add manually) looked like this:

Screenshot 2014-09-04 11.58.00

then for Vagrant setup:

Screenshot 2014-09-04 12.09.06

and the remote interpreter:

Screenshot 2014-09-04 12.08.45

PyCharm Django settings:

Screenshot 2014-09-04 12.07.49

 

Things I ran into

I was getting an error where it couldn’t find ROOT_URLCONF when running.  After adding that to the settings file, it was able to run.  But then I was getting InvalidCacheBackendError.

The issue ended up being that we have a base.py settings file, and then each user has a local.py settings file which extends it.  The “extending” didn’t seem to work.  So I made a new copy of the file called pycharm_django_settings.py in the same folder.  This file was just a copy of all the base.py settings and the local.py settings.  There may be a better way to do this, but this worked for me.

After creating that file, I had to set this for the PyCharm properties | django settings for that project to point to that new file.  But I ALSO had to set the DJANGO_SETTINGS_MODULE value above to point to that file.

After that, I was able to run our service in PyCharm and could start debugging!

Leave a comment