Create new Django applications with pizazz. π
- Interactive mode for creating new applications.
- Predefined structure for typical use cases:
- API
- website
- worker
- Create new Django applications based on a
startertemplate. - 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
- 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.
- 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" can be confusing for new developers, and creating a "project" without an "app" is an outlier.
- Knowing when to use either
django-adminormanage.pyis a common source of confusion. - The
DJANGO_SETTINGS_MODULEenvironment variable is flexible, but annoying to deal with; 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.
- Project-specific files, e.g.
settings.py, should be in aconfigdirectory. - When creating a new app in a project, it should automatically be added to
INSTALLED_APPS. - Tests should be written with
pytestand should be located in atestsdirectory under the project root. - Settings should be split into multiple files per environment (e.g.
config/settings/base.py,config/settings/production.py, etc.)
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
When no arguments are provided, django-new will prompt you for the application name and folder location.
uvx django-newuvx 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
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
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
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
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
Use the provided path to create a custom application.
uvx django-new --starter={path} [name] [folder]Starters 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_projectStarters from untrusted sources should be carefully inspected before use to prevent potential security issues.
Starters 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"
}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]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
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
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/
typerrich
just test