Project And App Structure Templates for Django.
You can use these templates by referring to their release files during project/app creation.
Preinstalled Django in your local python version is required.
Although this should be pretty self-explanatory, please remember to replace
<project_name>
and <app_name>
with your project/app name ;-) and (of
course, dear mrkf 😎) git init
ialize it.
django-admin startproject --template https://github.com/oryon-dominik/django-template/releases/download/latest/project_template_django.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql. <project_name> <directory>
Local python version:
python -c 'import os;import sys;from pathlib import Path;os.system(str((Path(sys.executable).parent / \"Scripts\" / \"django-admin\").resolve()) + \" startproject --template https://github.com/oryon-dominik/django-template/releases/download/latest/project_template_django.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. <project_name> .\")'
For any subsequent command (creating apps..) install the dependencies (poetry install
) and activate your virtual environment.
django-admin startproject --template https://github.com/oryon-dominik/django-template/releases/download/latest/project_template_cli.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. <project_name> <directory>
(will be created in the project's apps
folder)
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_default.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. <app_name>
- Add
'apps.<app_name>.apps.<app_name.capitalize()>Config'
toLOCAL_APPS
orPROJECT_APPS
inconfig.settings.base.apps.py
. - Add the apps routes to
urlpatterns
inconfig.urls.routes.py
like this:path('', include('apps.<app_name>.urls', namespace="<app_name>")),
.
(will be created in the project's apps
folder)
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_rest.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. <app_name>
- Add
'apps.<app_name>.apps.<app_name.capitalize()>Config'
toLOCAL_APPS
orPROJECT_APPS
inconfig.settings.base.apps.py
. - Add the apps routes to
urlpatterns
inconfig.urls.routes.py
like this:path('', include('apps.<app_name>.api.urls', namespace="<app_name>")),
.
(will be created in the project's apps
folder)
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_authentication.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. authentication
- In
config.urls.apis.py
commentpath('', include('apps.authentication.api.urls')),
in.
Authentication is checking blacklisted tokens (whitelisting is a BAD idea ;-P) and will have a slow default cache (database access) for production. If you only use one worker, you might want to switch to memory for development.
# for a database cache backend create the table
python manage.py createcachetable
(will be created in the project's apps
folder, please use a singluar name, that will be automatically pluralized - it's a crud app after all ;-] )
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_simple_crud_templates.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. --pluralize-name --replace-html <app_name>
- Add
'apps.<app_name>.apps.<app_name.capitalize()>Config'
toLOCAL_APPS
orPROJECT_APPS
inconfig.settings.base.apps.py
. - Add the apps routes to
urlpatterns
inconfig.urls.routes.py
like this:path('', include('apps.<app_name>.api.urls', namespace="<app_name>")),
. - Edit your
models.py
accordingly andmakemigrations
andmigrate
.
(will be created in the project's apps
folder, please use a singluar name)
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_vuejs_templates.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql,sh. --replace-html <app_name>
-
Add
'apps.<app_name>.apps.<app_name.capitalize()>Config'
toLOCAL_APPS
orPROJECT_APPS
inconfig.settings.base.apps.py
. -
Comment-In
'django_vite',
inTHIRD_PARTY_APPS
ofconfig.settings.base.apps.py
. -
In your
pyproject.toml
set[tool.poetry.group.vite][optional] = false
andpoetry install
the dependecieydjango-vite
. -
Add the apps routes to
urlpatterns
inconfig.urls.routes.py
like this:path('', include('apps.<app_name>.urls', namespace="<app_name>")),
. -
Create a frontend in
./frontend
, compiling to./frontend/dist
. -
You might clone the vuejs-template for a quick start.
git clone https://github.com/oryon-dominik/skeleton-vuejs-djangoexample/ ./frontend
(will be created in the project's apps
folder)
TODOs: after setting up the template:
- Comment out
"core.accounts"
inCORE_APPS
inconfig.settings.base.apps.py
(Line 14). - Comment in
"apps.accounts.apps.AccountsConfig",
inLOCAL_APPS
inconfig.settings.base.apps.py
(Line 26). - Comment in the apps routes to
urlpatterns
inconfig.urls.routes.py
(line 42) - Delete the
__init__.py
incore/accounts/migrations/
and runpython manage.py migrate
.
python manage.py startapp --template https://github.com/oryon-dominik/django-template/releases/download/latest/app_template_accounts.zip --extension=py,md,toml,yaml,yml,env,service,conf,sql. --replace-html accounts
The .pre-commit-config.yaml mypy hook needs a lot of dependencies, so you might want to clean it up a bit if your just using the minimal template.