django-click

raw JSON →
2.5.0 verified Fri May 01 auth: no python

Build Django management commands using the click CLI package. Version 2.5.0; supports Python >=3.10 and Django up to 6.0. Release cadence: infrequent, driven by compatibility updates.

pip install django-click
error ModuleNotFoundError: No module named 'django_click'
cause django-click is not installed.
fix
Run 'pip install django-click'.
error ImportError: cannot import name 'command' from 'django_click'
cause Old import path from django_click.decorators; the symbol moved to django_click.
fix
Use 'from django_click import command'.
error TypeError: command() missing 1 required positional argument: 'cls'
cause The @command decorator requires a BaseCommand subclass as first argument.
fix
Decorate with @command(BaseCommand) where BaseCommand is imported from django.core.management.base.
breaking Django-click 2.5.0 drops support for Python <3.10 and Django <4.2. Upgrade your environment if using older versions.
fix Upgrade Python to >=3.10 and Django to >=4.2, then install django-click 2.5.0.
gotcha Commands must be decorated with @command(BaseCommand) and the function name must be all lowercase, as it becomes the management command name.
fix Ensure the function name matches the command name (e.g., 'def my_command(...)').
deprecated The 'django_click.decorators' module is deprecated; import directly from 'django_click'.
fix Change 'from django_click.decorators import command' to 'from django_click import command'.

Create a Django management command named 'hello' using click decorators.

# my_app/management/commands/hello.py
from django.core.management.base import BaseCommand
from django_click import command
import click

@command(BaseCommand)
@click.option('--name', default='World')
def hello(name):
    click.echo(f'Hello {name}')