-
Use
Django-Cookiecutter
for a base project template -
App name should be a plural of the main model in the app, like
subscriptions
,payments
-
Always use
BaseModel
withid
(UUID),created_at
&updated_at
. Every model sub-classes this model -
Always use
AbstractUser
all the time, even though you don't need one -
Always use multiple
settings.py
files, likebase.py
,production.py
-
Use
DJANGO_SETTINGS_MODULE
variable in your.env
file -
Always use a
.env
file for managing keys and other secret info -
Always have multiple
requirements.txt
files:requirements/base.txt
,requirements/dev.txt
-
Always use
Django Debug Toolbar
for debugging -
Postgres
is the recommended database -
Make model
choices
constant -
Instead of
.get()
, useget_object_or_404
[only in views] -
Make good use of
Object.DoesNotExist
&Object.MultipleObjectsReturned
-
Use
transaction
for ATOMIC requests -
Use Class-based views wherever possible - check Django's Generic Class-based Views
-
Implement URL namespacing
-
Use
LoginRequiredMixin
for granting access to authenticated users in CBV -
Always use the name of the app as a directory for templates
-
User
AUTH_USER_MODEL
insettings.py
-
Other production settings available at https://gist.github.com/PraneethKarnena/d626eb91ef222d565f0f6a44cbb5cbde
Last active
June 6, 2022 01:11
-
-
Save PraneethKarnena/fcb19188fc6f742aa1bbe97abc59a26b to your computer and use it in GitHub Desktop.
Django Best Practices
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment