Skip to main content

Create a superuser if it doesn't exist, in the non interactive mode, using environment variables to set the email and password

Project description

Django Ensure Superuser

A simple Django management command to create a superuser non-interactively if one does not already exist.

This is useful for automating the setup of a Django application, for example, in a Docker container or a deployment script.

Installation

  1. Install the package using pip:
pip install django-ensuresuperuser
  1. Add django_ensuresuperuser to your INSTALLED_APPS setting in your Django project's settings.py:
INSTALLED_APPS = [
    # ...
    'django_ensuresuperuser',
]

Usage

Assuming all variables are set, run the management command:

python manage.py ensuresuperuser

Configuration

The command requires the following environment variables to be set:

  • DJANGO_SUPERUSER_PASSWORD: The password for the superuser.
  • DJANGO_SUPERUSER_EMAIL (optional): The email for the superuser. Defaults to admin@example.com.

The superuser will be created with the username admin. If a user with the username admin already exists, the command will do nothing.

Example

export DJANGO_SUPERUSER_PASSWORD="mysecretpassword"
export DJANGO_SUPERUSER_EMAIL="admin@mydomain.com"
python manage.py ensuresuperuser

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_ensuresuperuser-0.1.0.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

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

django_ensuresuperuser-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file django_ensuresuperuser-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for django_ensuresuperuser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 114677cc1ed7ec4f6fda75d34df73f88ca6754d54343d907cb848a67683499a3
MD5 108dc79fc8b2a07f08d7d940c9cba2c6
BLAKE2b-256 10ea1292c5ef621b02e252ac22c5e80a2a3120a46cd8d002ecab5979b045e67a

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_ensuresuperuser-0.1.0.tar.gz:

Publisher: python-package.yml on ChrisW-priv/django_ensuresuperuser

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_ensuresuperuser-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ensuresuperuser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f5df116532f3e9e4fa5c2e320662713ba9dbee11bf58eb764188676f77ae306
MD5 a38f0856defb037bb24771a99753b1ba
BLAKE2b-256 90e4da850b6a6a2ad425dcb1fefde9f5cbdcb57b2229e7f6dd6e355d6ac91858

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_ensuresuperuser-0.1.0-py3-none-any.whl:

Publisher: python-package.yml on ChrisW-priv/django_ensuresuperuser

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