This page is archived. Please visit https://countable-ops-manual.readthedocs.io/
These are things we've found to solve common issues an save lots of time.
Include version string in static assets paths loaded from the client.
<script src="script.js?v={{ settings.VERSION }}"></script>
In settings.py
set VERSION=os.system('git rev-parse HEAD')
This is a wonderful catchall to prevent client cache issues that waste so much time.
Use the long term support version of Django, ideally the latest one available at any given time.
This book contains a lot of great practices, which we almost universally agree with. In particular.
- Fat models, skinny views. Put more logic and code in Model methods, if it's relevant to that model specifically. Avoid large amounts of code in views.
Certain files in Django should only import from other certain types of files. For example, urls.py
should really only import from views.py
(and utils.py
).
Keep models normalized. (no duplicate data or extra foreign keys). Schema changes should be heavily reviewed by a senior dev as any bad designs here will cascade to other layers.
We generally use function based views (FBV) instead of class based views (CBV) at Countable. When using Django Rest Framework (DRF), this is an exception and we prefer CBV. Please do use DRF for substantial rest API work.
Avoid unnecessary nesting.
#unnecessary nesting:
def view(request):
if 'x' in request.GET:
if (another check):
return HttpResponse(...)
# better
def view(request):
if 'x' not in request.GET:
return Http400(...)
if not another check:
return Http400(...)
return HttpResponse(...)
- Django should have SMTP creds, and should set the ADMINS to the back-end developer that maintains that project.
- In prod and staging environments, set DEBUG=False, so the ADMINS get emails with any stack traces.