<commit_before>====================================
Writing custom django-admin commands
====================================

.. module:: django.core.management

Applications can register their own actions with ``manage.py``. For example,
you might want to add a ``manage.py`` action for a Django app that you're
distributing. In this document, we will be building a custom ``closepoll``
command for the ``polls`` application from the
:doc:`tutorial</intro/tutorial01>`.

To do this, just add a ``management/commands`` directory to the application.
Django will register a ``manage.py`` command for each Python module in that
directory whose name doesn't begin with an underscore. For example::

    polls/
        __init__.py
        models.py
        management/
            __init__.py
            commands/
                __init__.py
                _private.py
                closepoll.py
        tests.py
        views.py

In this example, the ``closepoll`` command will be made available to any project
that includes the ``polls`` application in :setting:`INSTALLED_APPS`.

The ``_private.py`` module will not be available as a management command.

The ``closepoll.py`` module has only one requirement -- it must define a class
``Command`` that extends :class:`BaseCommand` or one of its<commit_msg>[1.7.x] Fixed #22942 -- Noted that __init__.py files are required for management command detection.<commit_after>====================================
Writing custom django-admin commands
====================================

.. module:: django.core.management

Applications can register their own actions with ``manage.py``. For example,
you might want to add a ``manage.py`` action for a Django app that you're
distributing. In this document, we will be building a custom ``closepoll``
command for the ``polls`` application from the
:doc:`tutorial</intro/tutorial01>`.

To do this, just add a ``management/commands`` directory to the application.
Django will register a ``manage.py`` command for each Python module in that
directory whose name doesn't begin with an underscore. For example::

    polls/
        __init__.py
        models.py
        management/
            __init__.py
            commands/
                __init__.py
                _private.py
                closepoll.py
        tests.py
        views.py

On Python 2, be sure to include ``__init__.py`` files in both the
``management`` and ``management/commands`` directories as done above or your
command will not be detected.

In this example, the ``closepoll`` command will be made available to any project
that includes the ``polls`` application in :setting:`INSTALLED_APPS`.

The ``_private.py`` module will not be available as a management command.

The ``closepoll.py`` module has only one requirement -- it must define a class
``Command`` that extends :class:`BaseCommand` or one of its
{'fraction_non_alphanumeric': 0.1310848400556328, 'fraction_numerical': 0.004172461752433936, 'mean_word_length': 3.385670731707317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2545457', 'n_tokens_mistral': 743, 'n_tokens_neox': 697, 'n_words': 327}