Skip to main content

No project description provided

Project description

django-new โœจ

It is like django-admin startproject mysite djangotutorial, but better.

Features ๐Ÿš€

  • Create new Django projects based on typical use cases, e.g. API, website, worker.
  • Support "minimal" project types (aka DEP-15) for streamlined applications.
  • 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 - git ignore patterns
    • pyproject.toml - Python project configuration (PEP 621 compliant)
    • README.md - Project documentation

Goals ๐ŸŽฏ

  • Strike a balance between django-admin startproject / django-admin startapp and 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-admin or manage.py is a common source of confusion.
  • The DJANGO_SETTINGS_MODULE environment 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 a config directory.
  • When creating a new app, it should automatically be added to INSTALLED_APPS.
  • Tests should be written with pytest and should be located in a tests directory 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 has some opinions about the folder structure and what files are most useful for certain use cases. For example, config is used to store "project-level" files like settings.py. The --api, --web, and --worker flags can be used as an additional modifier to create a specific type of application.

Along with the typical Django files, django-new also creates a few typically used files (if they do not already exist) when creating a new project:

  • .env - Environment variables
  • .gitignore - git ignore patterns
  • pyproject.toml - Python project configuration (PEP 621 compliant)
  • README.md - Project 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 generic app

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

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 minimal project

django-new can create a "minimal" project with a single directory, similar to the ideas in DEP-15.

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 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.

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

django_new-0.2.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_new-0.2.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file django_new-0.2.0.tar.gz.

File metadata

  • Download URL: django_new-0.2.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_new-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3b3f76db80004aa4767828f04cbc8067871564bd536a8c488141423ddd3cdc16
MD5 4f4b94e08c38f35c7b952d6d76c65e54
BLAKE2b-256 5ea7ed2e6404f051fbef76f8c723be34697d96762abd687c81671b987076def4

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_new-0.2.0.tar.gz:

Publisher: publish.yml on adamghill/django-new

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_new-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_new-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_new-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82b8f087ed6e5716c527683d72e1bccd597f972a353b3ee0a590818b7dae617d
MD5 3609e7846501726e4150de60c5ffcf5b
BLAKE2b-256 fa33e22e38bc4c394678a39bb35f8dc826ed10f69f210476eb485b4f1057964d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_new-0.2.0-py3-none-any.whl:

Publisher: publish.yml on adamghill/django-new

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page