Create new Django applications with sensible defaults and modern patterns. ๐
Project description
django-new โจ
Create new Django applications with sensible defaults and modern patterns. ๐
Features ๐
- Create new Django applications based on typical use cases, e.g. API, website, worker.
- Create "minimal" projects (aka DEP-15) for a streamlined codebase.
- When creating new apps, automatically add them to
INSTALLED_APPS. - Create other files that are typically used in a Django project with sensible defaults:
.env- Environment variables.gitignore-gitignore patternspyproject.toml- Python project configuration (PEP 621 compliant)README.md- Project documentation
Goals ๐ฏ
- Strike a balance between
django-admin startproject/django-admin startappand more full-fledged starter projects. - Have some opinions about the structure for different use cases, but try to avoid prescribing specific libraries.
- Reduce the confusion between a "project" and "app".
- Be backwards-compatible with existing Django projects.
- Create folders and files automatically with sensible defaults for modern Python workflows that the majority of developers will need.
NOTE: this is a work in progress and is not yet ready for production use. If you are an expert Django developer, you might disagree with at least some of the opinions here. That's ok. There is a ton (too much?) of bike shedding around project creation. I am open to different opinions and feedback, but I am also focused on handling the 80/20 for new Django projects and provide some patterns based on my personal experience.
Guiding principles ๐ฏ๏ธ
- There are three main use cases for Django: website, API, and worker; they serve different use cases, and each has a unique (but defined) file structure.
- The distinction between "project" and "app" is unnecessarily confusing.
- Creating a "project" or "app" without the other doesn't happen that often, so it should be treated as an outlier, not the normal case.
- Knowing when to use either
django-adminormanage.pyis a common source of confusion. - The
DJANGO_SETTINGS_MODULEenvironment variable is too flexible and there should be simpler patterns for managing different environments. - Having a slightly non-ideal standard that mostly works for a majority of developers is better than no standard at all because it reduces cognitive load.
Hot takes ๐ฅ
- Project-specific files, e.g.
settings.py, should be in aconfigdirectory. - When creating a new app, it should automatically be added to
INSTALLED_APPS. - Tests should be written with
pytestand should be located in atestsdirectory under the root. - Settings should be split into multiple files per environment (e.g.
config/settings/base.py,config/settings/production.py, etc.)
Usage ๐
django-new is designed to be used with uvx or pipx.
uvx django-new [--api | --web | --worker] name [folder]
django-new creates a standard folder structure for different use cases (based on the --api, --web, or --worker flag) along with a config folder to store "project-level" files like settings.py. django-new also creates a few typically used files (if they do not already exist) when creating a new application:
.env- Local Environment variables.gitignore-gitconfigurationpyproject.toml- Configuration and dependenciesREADME.md- Documentation
Create a new API
uvx django-new --api name [folder]
.
โโโ api
โ โโโ migrations
โ โ โโโ __init__.py
โ โโโ __init__.py
โ โโโ admin.py
โ โโโ apps.py
โ โโโ models.py
โ โโโ urls.py
โ โโโ views.py
โโโ config
โ โโโ __init__.py
โ โโโ asgi.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ tests
โ โโโ __init__.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a new website
uvx django-new --web name [folder]
.
โโโ config
โ โโโ __init__.py
โ โโโ asgi.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ static
โ โโโ css
โ โโโ img
โ โโโ js
โโโ tests
โ โโโ __init__.py
โโโ web
โ โโโ migrations
โ โ โโโ __init__.py
โ โโโ templates
โ โโโ templatetags
โ โ โโโ __init__.py
โ โโโ __init__.py
โ โโโ admin.py
โ โโโ apps.py
โ โโโ models.py
โ โโโ urls.py
โ โโโ views.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a new worker
uvx django-new --worker name [folder]
.
โโโ config
โ โโโ __init__.py
โ โโโ asgi.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ tests
โ โโโ __init__.py
โโโ worker
โ โโโ migrations
โ โ โโโ __init__.py
โ โโโ __init__.py
โ โโโ admin.py
โ โโโ apps.py
โ โโโ models.py
โ โโโ tasks.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a new default application
uvx django-new name [folder]
.
โโโ config
โ โโโ __init__.py
โ โโโ asgi.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ {name}
โ โโโ migrations
โ โ โโโ __init__.py
โ โโโ __init__.py
โ โโโ admin.py
โ โโโ apps.py
โ โโโ models.py
โ โโโ urls.py
โ โโโ views.py
โโโ tests
โ โโโ __init__.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a new "minimal" application
Based on the minimal project in DEP-15, this will create a new Django project and app within a single directory.
uvx django-new --api --minimal name [folder]
uvx django-new --web --minimal name [folder]
uvx django-new --worker --minimal name [folder]
uvx django-new --minimal name [folder]
.
โโโ {name}
โ โโโ migrations
โ โ โโโ __init__.py
โ โโโ __init__.py
โ โโโ admin.py
โ โโโ apps.py
โ โโโ asgi.py
โ โโโ models.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ views.py
โ โโโ wsgi.py
โโโ tests
โ โโโ __init__.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a new application based on a starter kit
Starter kits will use the provided path to create a custom application.
uvx django-new --starter={path} name [folder]
Starter kits use the built-in Django
startproject --templatefunctionality under the hood.
The path passed into the starter option can be a directory, local archive file, or a remote URL. Remote URLs must point to an archive file using a http, https, or ftp protocol.
Supported archive file extensions:
.zip,.tar,.tar.gz,.tar.bz2,.tar.xz,.tar.lzma,.tgz,.tbz2,.txz,.tlz
uvx django-new --starter=https://github.com/githubuser/django-app-template/archive/main.zip new_project
Starter kits from untrusted sources should be carefully inspected before use to prevent potential security issues.
Variable replacement
Starter kits can use variables that will be replaced in the included .py files using Django template syntax, like {{ project_name }}.
The context used for variable replacement:
{
"project_name": "the project name provided to django-new, e.g. 'myproject'",
"project_directory": "full/path/to/the/myproject",
"secret_key": "a randomly generated secret key",
"docs_version": "version of the documentation",
"django_version": "version of Django"
}
Add new app to an existing Django project
If a project already exists in the specified folder, django-new will add a new app to it. Use the same flags as above to create a specific type of app.
uvx django-new --api name [folder]
uvx django-new --web name [folder]
uvx django-new --worker name [folder]
uvx django-new name [folder]
Create a bare project
When a non-project folder is specified and an app should not be created, use the --project flag.
uvx django-new --project name [folder]
.
โโโ config
โ โโโ __init__.py
โ โโโ asgi.py
โ โโโ settings.py
โ โโโ urls.py
โ โโโ wsgi.py
โโโ tests
โ โโโ __init__.py
โโโ .env
โโโ .gitignore
โโโ manage.py
โโโ pyproject.toml
โโโ README.md
Create a bare app
When a non-project folder is specified and a project should not be created, use the --app flag.
uvx django-new --app name [folder]
.
โโโ {name}
โโโ migrations
โ โโโ __init__.py
โโโ __init__.py
โโโ admin.py
โโโ apps.py
โโโ models.py
โโโ urls.py
โโโ views.py
Project vs app terminology confusion
Django's use of "project" and "app" can sometimes cause confusion.
More details about the distinction between "project" and "app" are in the Django documentation.
Inspiration โค๏ธ
Heavily inspired by DEP-15, although it approaches the solution from a different angle.
- DEP-15
- knyghty's django-new
- DEP-15 discussion
- startapp template discussion
- https://epicserve.com/django/2024/10/24/improving-the-new-django-developer-experience.html
- https://www.mostlypython.com/django-from-first-principles/
Tests
just test
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_new-0.3.0.tar.gz.
File metadata
- Download URL: django_new-0.3.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
212b16c13296fddef59c37feb69cf90165f9cd8b2b30d26efb5cbf830e4a40c7
|
|
| MD5 |
2129855c3f531113032efc5df4bf8888
|
|
| BLAKE2b-256 |
08c6705b19f5a03e3eaefe22d40a5e1b33d0ff33706e92805e5097b72f9f7c3d
|
Provenance
The following attestation bundles were made for django_new-0.3.0.tar.gz:
Publisher:
publish.yml on adamghill/django-new
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_new-0.3.0.tar.gz -
Subject digest:
212b16c13296fddef59c37feb69cf90165f9cd8b2b30d26efb5cbf830e4a40c7 - Sigstore transparency entry: 732068788
- Sigstore integration time:
-
Permalink:
adamghill/django-new@cf92af646b74e5277eceba5d8bdafd6db67c3b17 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf92af646b74e5277eceba5d8bdafd6db67c3b17 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_new-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_new-0.3.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd5a5b06e0bec84ed3ce7d3323d2c4f1052ea7187786d4ead7c429a2dbe94db9
|
|
| MD5 |
aad8efb4de454d71b35ba984205a8533
|
|
| BLAKE2b-256 |
07b7cd27c55c71bfa892af3c46c46bb4b8cde9113640416ff42bb1c941b5f26d
|
Provenance
The following attestation bundles were made for django_new-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on adamghill/django-new
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_new-0.3.0-py3-none-any.whl -
Subject digest:
cd5a5b06e0bec84ed3ce7d3323d2c4f1052ea7187786d4ead7c429a2dbe94db9 - Sigstore transparency entry: 732068791
- Sigstore integration time:
-
Permalink:
adamghill/django-new@cf92af646b74e5277eceba5d8bdafd6db67c3b17 -
Branch / Tag:
refs/tags/0.3.0 - Owner: https://github.com/adamghill
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf92af646b74e5277eceba5d8bdafd6db67c3b17 -
Trigger Event:
release
-
Statement type: