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:
- Generate a Django project with the cookiecutter
- Run the tests of the created project
- Ensure
flake8
cleanliness - Ensure 100% test coverage
- Ensure
- Use honcho to run Django via the Procfile and test that it’s started ok
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:
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
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.
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…?
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!