Kristian Glass - Do I Smell Burning?

My Django Project Template

I made a Django project template.

First things first: I don’t think you should use my Django project template for your Django projects. In fact, much like with dotfiles, I don’t think you should ever just use someone else’s template. In the spirit of Yes Minister’s irregular verbs: “I make careful and opinionated curations, you make poor choices, they add pointless bloat”.

What can be useful though, is using them for inspiration and ideas, and I definitely think mine has some things worth taking.

Testing

I’m really quite happy with my test setup. Roughly, it’s:

Unfortunately it turns out running the WSGI server with honcho with tox with CircleCI leads to some fun with paths / CWD, and I thus don’t yet have gunicorn working with the test suite, but hopefully I’ll work that out soon!

The generated project has one test, and here it is:

from django.test import TestCase

class BasicTestCase(TestCase):
    def test_getting_root(self):
        self.client.get('/')

That one little test is my favourite - five lines exercising so much: does (most of) the service start, are the settings ok, is the root URL config ok, and more.

Directory Layout

$ tree
.
├── LICENSE
├── Procfile
├── README.md
├── loremipsum
│   ├── loremipsum
│   │   ├── __init__.py
│   │   ├── settings.py
│   │   ├── tests
│   │   │   ├── __init__.py
│   │   │   └── test_basic.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   └── manage.py
├── requirements-test.txt
├── requirements.txt
└── tox.ini

I keep my Django workspace as a subdirectory of the git root. This keeps my Django project isolated from other bits of metadata; equivalent to a src dir, if you will.

Necessary? Nope. Objective benefits? Not really. Do I like it and recommend it for the compartmentalisation? Sure.

django12factor

Because you should be getting config from the environment.

No really, you should.

(I may be slightly biased…)

WhiteNoise

I used to always use S3 for my static files, now I use WhiteNoise, because stand-alone apps are awesome, as is a nice simple build stage.

And more…?

No, not much more.

I need to fix my gunicorn tests, and sort out django-secure, but that’s pretty much it for “things I use in everything”.

Would you recommend anything else? Drop me a tweet!

Comments