Django Development and Staging

I have two boxes: dev and production. I need a very simple method for working on the dev machine and then pushing to production.


Use direnv to maintain environment based on directory.

Use two seperate .envrc files on dev and production. Don’t check-in to


Create a test case:

# phisaverweb/

class TestEmails(TestCase):
    fixtures = ['phisaverweb/fixtures/email-tests.json']

    def test_send(self):
        print ("hi")

Tests use a seperate database. To get data to test against, it’s best to programmatically create it.

But I used fixtures. First, dump the current database. If you get “django test fixtures contenttypes.ContentType unique constraint duplicate key” type error, I don’t understand why but “natural primary” and “natural foreign” (see below) fixes it:

python dumpdata --indent 4 --natural-primary --natural-foreign > phisaverweb/fixtures/email-tests.json

Then run the tests via python tests. In VSCode you can make a launch task:

            "name": "Django Tests",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/",
            "args": [
                "--keepdb", # don't destroy db on exit
                "phisaverweb.tests" # run just these tests
            "django": true,
            "env": {"PYTHONPATH":"${workspaceFolder}/.."}

Leave a Reply

Your email address will not be published.