{"title":"Jak napisać własne komendy django-admin","version":"4.2","locale":"pl","docname":"howto/custom-management-commands","url":"/pl/4.2/howto/custom-management-commands/","canonical":"https://djangodocs.dev/pl/4.2/howto/custom-management-commands/","summary":"Aplikacje mogą rejestrować swoje własne akcje w manage.py . Na przykład mógłbyś chcieć dodać akcję manage.py dla aplikacji Django, którą udostępniasz. W tym…","html":"<span id=\"how-to-create-custom-django-admin-commands\"></span><h1>Jak napisać własne komendy <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code><a class=\"heading-anchor\" href=\"#module-django.core.management\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Aplikacje mogą rejestrować swoje własne akcje w <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code>. Na przykład mógłbyś chcieć dodać akcję <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> dla aplikacji Django, którą udostępniasz. W tym dokumencie będziemy budować własną komendę <code class=\"docutils literal notranslate\"><span class=\"pre\">closepoll</span></code> dla aplikacji <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> z <a class=\"reference internal\" href=\"/pl/4.2/intro/tutorial01/\"><span class=\"doc\">samouczka</span></a>.</p>\n<p>To do this, add a <code class=\"docutils literal notranslate\"><span class=\"pre\">management/commands</span></code> directory to the application. Django\nwill register a <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> command for each Python module in that directory\nwhose name doesn’t begin with an underscore. For example:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>polls/\n    __init__.py\n    models.py\n    management/\n        __init__.py\n        commands/\n            __init__.py\n            _private.py\n            closepoll.py\n    tests.py\n    views.py\n</code></pre></div>\n<p>W tym przykładzie komenda <code class=\"docutils literal notranslate\"><span class=\"pre\">closepoll</span></code> stanie się dostępna dla każdego projektu, który umieści aplikację <code class=\"docutils literal notranslate\"><span class=\"pre\">polls</span></code> w <a class=\"reference internal\" href=\"/pl/4.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>.</p>\n<p>Moduł <code class=\"docutils literal notranslate\"><span class=\"pre\">_private.py</span></code> nie będzie dostępny jako komenda zarządzania.</p>\n<p>Jest tylko jedno wymaganie dla <code class=\"docutils literal notranslate\"><span class=\"pre\">closepoll.py</span></code> – musi definiować klasę <code class=\"docutils literal notranslate\"><span class=\"pre\">Command</span></code>, która dziedziczy po <a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a> lub jednej z jej <a class=\"reference internal\" href=\"#ref-basecommand-subclasses\"><span class=\"std std-ref\">podklas</span></a>.</p>\n<aside class=\"admonition-standalone-scripts admonition\">\n<p class=\"admonition-title\">Samodzielne skrypty</p>\n<p>Własne komendy zarządcze są szczególnie przydatne w odpalaniu samodzielnych skryptów lub skryptów wykonywanych cyklicznie z tabeli programu cron Uniksa lub z panelu kontrolnego harmonogramu zadań Windows.</p>\n</aside>\n<p>Aby zaimplementować komendę, zmień <code class=\"docutils literal notranslate\"><span class=\"pre\">polls/management/commands/closepoll.py</span></code>, aby wyglądał w ten sposób:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.core.management.base</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">BaseCommand</span><span class=\"p\">,</span> <span class=\"n\">CommandError</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">polls.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">Question</span> <span class=\"k\">as</span> <span class=\"n\">Poll</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Command</span><span class=\"p\">(</span><span class=\"n\">BaseCommand</span><span class=\"p\">):</span>\n    <span class=\"n\">help</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Closes the specified poll for voting&quot;</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">add_arguments</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">parser</span><span class=\"p\">):</span>\n        <span class=\"n\">parser</span><span class=\"o\">.</span><span class=\"n\">add_argument</span><span class=\"p\">(</span><span class=\"s2\">&quot;poll_ids&quot;</span><span class=\"p\">,</span> <span class=\"n\">nargs</span><span class=\"o\">=</span><span class=\"s2\">&quot;+&quot;</span><span class=\"p\">,</span> <span class=\"nb\">type</span><span class=\"o\">=</span><span class=\"nb\">int</span><span class=\"p\">)</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">handle</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">options</span><span class=\"p\">):</span>\n        <span class=\"k\">for</span> <span class=\"n\">poll_id</span> <span class=\"ow\">in</span> <span class=\"n\">options</span><span class=\"p\">[</span><span class=\"s2\">&quot;poll_ids&quot;</span><span class=\"p\">]:</span>\n            <span class=\"k\">try</span><span class=\"p\">:</span>\n                <span class=\"n\">poll</span> <span class=\"o\">=</span> <span class=\"n\">Poll</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"n\">pk</span><span class=\"o\">=</span><span class=\"n\">poll_id</span><span class=\"p\">)</span>\n            <span class=\"k\">except</span> <span class=\"n\">Poll</span><span class=\"o\">.</span><span class=\"n\">DoesNotExist</span><span class=\"p\">:</span>\n                <span class=\"k\">raise</span> <span class=\"n\">CommandError</span><span class=\"p\">(</span><span class=\"s1\">&#39;Poll &quot;</span><span class=\"si\">%s</span><span class=\"s1\">&quot; does not exist&#39;</span> <span class=\"o\">%</span> <span class=\"n\">poll_id</span><span class=\"p\">)</span>\n\n            <span class=\"n\">poll</span><span class=\"o\">.</span><span class=\"n\">opened</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n            <span class=\"n\">poll</span><span class=\"o\">.</span><span class=\"n\">save</span><span class=\"p\">()</span>\n\n            <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">stdout</span><span class=\"o\">.</span><span class=\"n\">write</span><span class=\"p\">(</span>\n                <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">style</span><span class=\"o\">.</span><span class=\"n\">SUCCESS</span><span class=\"p\">(</span><span class=\"s1\">&#39;Successfully closed poll &quot;</span><span class=\"si\">%s</span><span class=\"s1\">&quot;&#39;</span> <span class=\"o\">%</span> <span class=\"n\">poll_id</span><span class=\"p\">)</span>\n            <span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" id=\"management-commands-output\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>Gdy używasz komend zarządczych i chcesz pisać na konsolę, powinieneś pisać na <code class=\"docutils literal notranslate\"><span class=\"pre\">self.stdout</span></code> i <code class=\"docutils literal notranslate\"><span class=\"pre\">self.stderr</span></code>, zamiast drukować bezpośrednio na <code class=\"docutils literal notranslate\"><span class=\"pre\">stdout</span></code> i <code class=\"docutils literal notranslate\"><span class=\"pre\">stderr</span></code>. Przy użyciu tych proxy, testowanie twojej komendy staje się dużo prostsze. Zwróć też uwagę, że nie potrzebujesz kończyć wiadomości znakiem końca linii. Zostanie on dodany automatycznie, chyba że podasz parametr <code class=\"docutils literal notranslate\"><span class=\"pre\">ending</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">stdout</span><span class=\"o\">.</span><span class=\"n\">write</span><span class=\"p\">(</span><span class=\"s2\">&quot;Unterminated line&quot;</span><span class=\"p\">,</span> <span class=\"n\">ending</span><span class=\"o\">=</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</aside>\n<p>The new custom command can be called using <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">manage.py</span> <span class=\"pre\">closepoll</span>\n<span class=\"pre\">&lt;poll_ids&gt;</span></code>.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">handle()</span></code> method takes one or more <code class=\"docutils literal notranslate\"><span class=\"pre\">poll_ids</span></code> and sets <code class=\"docutils literal notranslate\"><span class=\"pre\">poll.opened</span></code>\nto <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> for each one. If the user referenced any nonexistent polls, a\n<a class=\"reference internal\" href=\"#django.core.management.CommandError\" title=\"django.core.management.CommandError\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">CommandError</span></code></a> is raised. The <code class=\"docutils literal notranslate\"><span class=\"pre\">poll.opened</span></code> attribute does not exist in\nthe <a class=\"reference internal\" href=\"/pl/4.2/intro/tutorial02/\"><span class=\"doc\">tutorial</span></a> and was added to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">polls.models.Question</span></code> for this example.</p>\n<section id=\"accepting-optional-arguments\">\n<span id=\"custom-commands-options\"></span><h2>Akceptowanie opcjonalnych argumentów<a class=\"heading-anchor\" href=\"#accepting-optional-arguments\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The same <code class=\"docutils literal notranslate\"><span class=\"pre\">closepoll</span></code> could be easily modified to delete a given poll instead\nof closing it by accepting additional command line options. These custom\noptions can be added in the <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.add_arguments\" title=\"django.core.management.BaseCommand.add_arguments\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">add_arguments()</span></code></a> method like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Command</span><span class=\"p\">(</span><span class=\"n\">BaseCommand</span><span class=\"p\">):</span>\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">add_arguments</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">parser</span><span class=\"p\">):</span>\n        <span class=\"c1\"># Positional arguments</span>\n        <span class=\"n\">parser</span><span class=\"o\">.</span><span class=\"n\">add_argument</span><span class=\"p\">(</span><span class=\"s2\">&quot;poll_ids&quot;</span><span class=\"p\">,</span> <span class=\"n\">nargs</span><span class=\"o\">=</span><span class=\"s2\">&quot;+&quot;</span><span class=\"p\">,</span> <span class=\"nb\">type</span><span class=\"o\">=</span><span class=\"nb\">int</span><span class=\"p\">)</span>\n\n        <span class=\"c1\"># Named (optional) arguments</span>\n        <span class=\"n\">parser</span><span class=\"o\">.</span><span class=\"n\">add_argument</span><span class=\"p\">(</span>\n            <span class=\"s2\">&quot;--delete&quot;</span><span class=\"p\">,</span>\n            <span class=\"n\">action</span><span class=\"o\">=</span><span class=\"s2\">&quot;store_true&quot;</span><span class=\"p\">,</span>\n            <span class=\"n\">help</span><span class=\"o\">=</span><span class=\"s2\">&quot;Delete poll instead of closing it&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">)</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">handle</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">options</span><span class=\"p\">):</span>\n        <span class=\"c1\"># ...</span>\n        <span class=\"k\">if</span> <span class=\"n\">options</span><span class=\"p\">[</span><span class=\"s2\">&quot;delete&quot;</span><span class=\"p\">]:</span>\n            <span class=\"n\">poll</span><span class=\"o\">.</span><span class=\"n\">delete</span><span class=\"p\">()</span>\n        <span class=\"c1\"># ...</span>\n</code></pre></div>\n<p>The option (<code class=\"docutils literal notranslate\"><span class=\"pre\">delete</span></code> in our example) is available in the options dict\nparameter of the handle method. See the <a class=\"reference external\" href=\"https://docs.python.org/3/library/argparse.html#module-argparse\" title=\"(w Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">argparse</span></code></a> Python documentation\nfor more about <code class=\"docutils literal notranslate\"><span class=\"pre\">add_argument</span></code> usage.</p>\n<p>In addition to being able to add custom command line options, all\n<a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/\"><span class=\"doc\">management commands</span></a> can accept some default options\nsuch as <a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#cmdoption-verbosity\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">--verbosity</span></code></a> and <a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#cmdoption-traceback\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">--traceback</span></code></a>.</p>\n</section>\n<section id=\"management-commands-and-locales\">\n<span id=\"id1\"></span><h2>Management commands and locales<a class=\"heading-anchor\" href=\"#management-commands-and-locales\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>By default, management commands are executed with the current active locale.</p>\n<p>If, for some reason, your custom management command must run without an active\nlocale (for example, to prevent translated content from being inserted into\nthe database), deactivate translations using the <code class=\"docutils literal notranslate\"><span class=\"pre\">&#64;no_translations</span></code>\ndecorator on your <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.handle\" title=\"django.core.management.BaseCommand.handle\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle()</span></code></a> method:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.core.management.base</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">BaseCommand</span><span class=\"p\">,</span> <span class=\"n\">no_translations</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Command</span><span class=\"p\">(</span><span class=\"n\">BaseCommand</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"nd\">@no_translations</span>\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">handle</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">options</span><span class=\"p\">):</span>\n        <span class=\"o\">...</span>\n</code></pre></div>\n<p>Since translation deactivation requires access to configured settings, the\ndecorator can’t be used for commands that work without configured settings.</p>\n</section>\n<section id=\"testing\">\n<h2>Testowanie<a class=\"heading-anchor\" href=\"#testing\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Information on how to test custom management commands can be found in the\n<a class=\"reference internal\" href=\"/pl/4.2/topics/testing/tools/#topics-testing-management-commands\"><span class=\"std std-ref\">testing docs</span></a>.</p>\n</section>\n<section id=\"overriding-commands\">\n<h2>Nadpisywanie komend<a class=\"heading-anchor\" href=\"#overriding-commands\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django registers the built-in commands and then searches for commands in\n<a class=\"reference internal\" href=\"/pl/4.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> in reverse. During the search, if a command name\nduplicates an already registered command, the newly discovered command\noverrides the first.</p>\n<p>In other words, to override a command, the new command must have the same name\nand its app must be before the overridden command’s app in\n<a class=\"reference internal\" href=\"/pl/4.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>.</p>\n<p>Management commands from third-party apps that have been unintentionally\noverridden can be made available under a new name by creating a new command in\none of your project’s apps (ordered before the third-party app in\n<a class=\"reference internal\" href=\"/pl/4.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>) which imports the <code class=\"docutils literal notranslate\"><span class=\"pre\">Command</span></code> of the overridden\ncommand.</p>\n</section>\n<section id=\"command-objects\">\n<h2>Obiekty komend<a class=\"heading-anchor\" href=\"#command-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">BaseCommand</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>The base class from which all management commands ultimately derive.</p>\n<p>Use this class if you want access to all of the mechanisms which\nparse the command-line arguments and work out what code to call in\nresponse; if you don’t need to change any of that behavior,\nconsider using one of its <a class=\"reference internal\" href=\"#ref-basecommand-subclasses\"><span class=\"std std-ref\">subclasses</span></a>.</p>\n<p>Subclassing the <a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a> class requires that you implement the\n<a class=\"reference internal\" href=\"#django.core.management.BaseCommand.handle\" title=\"django.core.management.BaseCommand.handle\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle()</span></code></a> method.</p>\n<section id=\"attributes\">\n<h3>Atrybuty<a class=\"heading-anchor\" href=\"#attributes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>All attributes can be set in your derived class and can be used in\n<a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a>’s <a class=\"reference internal\" href=\"#ref-basecommand-subclasses\"><span class=\"std std-ref\">subclasses</span></a>.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.help\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">help</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.help\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A short description of the command, which will be printed in the\nhelp message when the user runs the command\n<code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">manage.py</span> <span class=\"pre\">help</span> <span class=\"pre\">&lt;command&gt;</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.missing_args_message\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">missing_args_message</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.missing_args_message\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If your command defines mandatory positional arguments, you can customize\nthe message error returned in the case of missing arguments. The default is\noutput by <a class=\"reference external\" href=\"https://docs.python.org/3/library/argparse.html#module-argparse\" title=\"(w Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">argparse</span></code></a> („too few arguments”).</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.output_transaction\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">output_transaction</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.output_transaction\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A boolean indicating whether the command outputs SQL statements; if\n<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, the output will automatically be wrapped with <code class=\"docutils literal notranslate\"><span class=\"pre\">BEGIN;</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">COMMIT;</span></code>. Default value is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.requires_migrations_checks\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">requires_migrations_checks</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.requires_migrations_checks\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A boolean; if <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, the command prints a warning if the set of\nmigrations on disk don’t match the migrations in the database. A warning\ndoesn’t prevent the command from executing. Default value is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.requires_system_checks\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">requires_system_checks</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.requires_system_checks\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A list or tuple of tags, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">[Tags.staticfiles,</span> <span class=\"pre\">Tags.models]</span></code>. System\nchecks <a class=\"reference internal\" href=\"/pl/4.2/topics/checks/#registering-labeling-checks\"><span class=\"std std-ref\">registered in the chosen tags</span></a>\nwill be checked for errors prior to executing the command. The value\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'__all__'</span></code> can be used to specify that all system checks should be\nperformed. Default value is <code class=\"docutils literal notranslate\"><span class=\"pre\">'__all__'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.style\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">style</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.style\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>An instance attribute that helps create colored output when writing to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">stdout</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">stderr</span></code>. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">stdout</span><span class=\"o\">.</span><span class=\"n\">write</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">style</span><span class=\"o\">.</span><span class=\"n\">SUCCESS</span><span class=\"p\">(</span><span class=\"s2\">&quot;...&quot;</span><span class=\"p\">))</span>\n</code></pre></div>\n<p>See <a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#syntax-coloring\"><span class=\"std std-ref\">Syntax coloring</span></a> to learn how to modify the color palette and to\nsee the available styles (use uppercased versions of the „roles” described\nin that section).</p>\n<p>If you pass the <a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#cmdoption-no-color\"><code class=\"xref std std-option docutils literal notranslate\"><span class=\"pre\">--no-color</span></code></a> option when running your command, all\n<code class=\"docutils literal notranslate\"><span class=\"pre\">self.style()</span></code> calls will return the original string uncolored.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.suppressed_base_arguments\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">suppressed_base_arguments</span></span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.suppressed_base_arguments\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The default command options to suppress in the help output. This should be\na set of option names (e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">'--verbosity'</span></code>). The default values for the\nsuppressed options are still passed.</p>\n</dd></dl>\n\n</section>\n<section id=\"methods\">\n<h3>Metody<a class=\"heading-anchor\" href=\"#methods\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a> has a few methods that can be overridden but only\nthe <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.handle\" title=\"django.core.management.BaseCommand.handle\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle()</span></code></a> method must be implemented.</p>\n<aside class=\"admonition-implementing-a-constructor-in-a-subclass admonition\">\n<p class=\"admonition-title\">Implementing a constructor in a subclass</p>\n<p>If you implement <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__</span></code> in your subclass of <a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a>,\nyou must call <a class=\"reference internal\" href=\"#django.core.management.BaseCommand\" title=\"django.core.management.BaseCommand\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code></a>’s <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Command</span><span class=\"p\">(</span><span class=\"n\">BaseCommand</span><span class=\"p\">):</span>\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">kwargs</span><span class=\"p\">):</span>\n        <span class=\"nb\">super</span><span class=\"p\">()</span><span class=\"o\">.</span><span class=\"fm\">__init__</span><span class=\"p\">(</span><span class=\"o\">*</span><span class=\"n\">args</span><span class=\"p\">,</span> <span class=\"o\">**</span><span class=\"n\">kwargs</span><span class=\"p\">)</span>\n        <span class=\"c1\"># ...</span>\n</code></pre></div>\n</aside>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.create_parser\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">create_parser</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">prog_name</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">subcommand</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">kwargs</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.create_parser\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a <code class=\"docutils literal notranslate\"><span class=\"pre\">CommandParser</span></code> instance, which is an\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser\" title=\"(w Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ArgumentParser</span></code></a> subclass with a few customizations for\nDjango.</p>\n<p>You can customize the instance by overriding this method and calling\n<code class=\"docutils literal notranslate\"><span class=\"pre\">super()</span></code> with <code class=\"docutils literal notranslate\"><span class=\"pre\">kwargs</span></code> of <a class=\"reference external\" href=\"https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser\" title=\"(w Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ArgumentParser</span></code></a> parameters.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.add_arguments\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">add_arguments</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">parser</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.add_arguments\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Entry point to add parser arguments to handle command line arguments passed\nto the command. Custom commands should override this method to add both\npositional and optional arguments accepted by the command. Calling\n<code class=\"docutils literal notranslate\"><span class=\"pre\">super()</span></code> is not needed when directly subclassing <code class=\"docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.get_version\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_version</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.get_version\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the Django version, which should be correct for all built-in Django\ncommands. User-supplied commands can override this method to return their\nown version.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.execute\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">execute</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">*</span></span><span class=\"n\"><span class=\"pre\">args</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">options</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.execute\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Tries to execute this command, performing system checks if needed (as\ncontrolled by the <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.requires_system_checks\" title=\"django.core.management.BaseCommand.requires_system_checks\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">requires_system_checks</span></code></a> attribute). If the command\nraises a <a class=\"reference internal\" href=\"#django.core.management.CommandError\" title=\"django.core.management.CommandError\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">CommandError</span></code></a>, it’s intercepted and printed to <code class=\"docutils literal notranslate\"><span class=\"pre\">stderr</span></code>.</p>\n</dd></dl>\n\n<aside class=\"admonition-calling-a-management-command-in-your-code admonition\">\n<p class=\"admonition-title\">Wywoływanie komendy zarządzającej w Twoim kodzie</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">execute()</span></code> should not be called directly from your code to execute a\ncommand. Use <a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#django.core.management.call_command\" title=\"django.core.management.call_command\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">call_command()</span></code></a> instead.</p>\n</aside>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.handle\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">handle</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">*</span></span><span class=\"n\"><span class=\"pre\">args</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">options</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.handle\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The actual logic of the command. Subclasses must implement this method.</p>\n<p>It may return a string which will be printed to <code class=\"docutils literal notranslate\"><span class=\"pre\">stdout</span></code> (wrapped\nby <code class=\"docutils literal notranslate\"><span class=\"pre\">BEGIN;</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">COMMIT;</span></code> if <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.output_transaction\" title=\"django.core.management.BaseCommand.output_transaction\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">output_transaction</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>).</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.BaseCommand.check\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">BaseCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">check</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_configs</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">tags</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">display_num_errors</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">False</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.BaseCommand.check\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Uses the system check framework to inspect the entire Django project for\npotential problems. Serious problems are raised as a <a class=\"reference internal\" href=\"#django.core.management.CommandError\" title=\"django.core.management.CommandError\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">CommandError</span></code></a>;\nwarnings are output to <code class=\"docutils literal notranslate\"><span class=\"pre\">stderr</span></code>; minor notifications are output to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">stdout</span></code>.</p>\n<p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">app_configs</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">tags</span></code> are both <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>, all system checks are\nperformed. <code class=\"docutils literal notranslate\"><span class=\"pre\">tags</span></code> can be a list of check tags, like <code class=\"docutils literal notranslate\"><span class=\"pre\">compatibility</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code>.</p>\n</dd></dl>\n\n</section>\n<section id=\"basecommand-subclasses\">\n<span id=\"ref-basecommand-subclasses\"></span><h3><code class=\"docutils literal notranslate\"><span class=\"pre\">BaseCommand</span></code> subclasses<a class=\"heading-anchor\" href=\"#basecommand-subclasses\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.AppCommand\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">AppCommand</span></span><a class=\"heading-anchor\" href=\"#django.core.management.AppCommand\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A management command which takes one or more installed application labels as\narguments, and does something with each of them.</p>\n<p>Rather than implementing <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.handle\" title=\"django.core.management.BaseCommand.handle\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle()</span></code></a>, subclasses must\nimplement <a class=\"reference internal\" href=\"#django.core.management.AppCommand.handle_app_config\" title=\"django.core.management.AppCommand.handle_app_config\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle_app_config()</span></code></a>, which will be called once for\neach application.</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.AppCommand.handle_app_config\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">handle_app_config</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_config</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">options</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.AppCommand.handle_app_config\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Perform the command’s actions for <code class=\"docutils literal notranslate\"><span class=\"pre\">app_config</span></code>, which will be an\n<a class=\"reference internal\" href=\"/pl/4.2/ref/applications/#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instance corresponding to an application\nlabel given on the command line.</p>\n</dd></dl>\n\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.LabelCommand\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">LabelCommand</span></span><a class=\"heading-anchor\" href=\"#django.core.management.LabelCommand\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A management command which takes one or more arbitrary arguments (labels) on\nthe command line, and does something with each of them.</p>\n<p>Rather than implementing <a class=\"reference internal\" href=\"#django.core.management.BaseCommand.handle\" title=\"django.core.management.BaseCommand.handle\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle()</span></code></a>, subclasses must implement\n<a class=\"reference internal\" href=\"#django.core.management.LabelCommand.handle_label\" title=\"django.core.management.LabelCommand.handle_label\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">handle_label()</span></code></a>, which will be called once for each label.</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.LabelCommand.label\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">LabelCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">label</span></span><a class=\"heading-anchor\" href=\"#django.core.management.LabelCommand.label\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A string describing the arbitrary arguments passed to the command. The\nstring is used in the usage text and error messages of the command.\nDefaults to <code class=\"docutils literal notranslate\"><span class=\"pre\">'label'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.LabelCommand.handle_label\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">LabelCommand.</span></span><span class=\"sig-name descname\"><span class=\"pre\">handle_label</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">label</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">options</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.LabelCommand.handle_label\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Wykonuje działania komendy dla etykiety``label``, którą będzie łańcuch podany w linii komend.</p>\n</dd></dl>\n\n</section>\n<section id=\"command-exceptions\">\n<h3>Wyjątki komend<a class=\"heading-anchor\" href=\"#command-exceptions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py exception\">\n<dt class=\"sig sig-object py\" id=\"django.core.management.CommandError\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">exception</span></span><span class=\"w\"> </span></em><span class=\"sig-name descname\"><span class=\"pre\">CommandError</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">returncode</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">1</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.management.CommandError\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Klasa wyjątków wskazująca na problem podczas wykonywania polecenia zarządzania.</p>\n<p>If this exception is raised during the execution of a management command from a\ncommand line console, it will be caught and turned into a nicely-printed error\nmessage to the appropriate output stream (i.e., <code class=\"docutils literal notranslate\"><span class=\"pre\">stderr</span></code>); as a result,\nraising this exception (with a sensible description of the error) is the\npreferred way to indicate that something has gone wrong in the execution of a\ncommand. It accepts the optional <code class=\"docutils literal notranslate\"><span class=\"pre\">returncode</span></code> argument to customize the exit\nstatus for the management command to exit with, using <a class=\"reference external\" href=\"https://docs.python.org/3/library/sys.html#sys.exit\" title=\"(w Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">sys.exit()</span></code></a>.</p>\n<p>If a management command is called from code through\n<a class=\"reference internal\" href=\"/pl/4.2/ref/django-admin/#django.core.management.call_command\" title=\"django.core.management.call_command\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">call_command()</span></code></a>, it’s up to you to catch the\nexception when needed.</p>\n</section>\n</section>","rootId":"module-django.core.management","toc":[{"title":"Akceptowanie opcjonalnych argumentów","anchor":"accepting-optional-arguments","children":[]},{"title":"Management commands and locales","anchor":"management-commands-and-locales","children":[]},{"title":"Testowanie","anchor":"testing","children":[]},{"title":"Nadpisywanie komend","anchor":"overriding-commands","children":[]},{"title":"Obiekty komend","anchor":"command-objects","children":[{"title":"Atrybuty","anchor":"attributes","children":[]},{"title":"Metody","anchor":"methods","children":[]},{"title":"BaseCommand subclasses","anchor":"basecommand-subclasses","children":[]},{"title":"Wyjątki komend","anchor":"command-exceptions","children":[]}]}],"breadcrumbs":[{"docname":"howto/index","title":"Przewodniki „Jak to zrobić”","url":"/pl/4.2/howto/"}],"prev":{"docname":"howto/csrf","title":"Jak używać ochrony CSRF w Django","url":"/pl/4.2/howto/csrf/"},"next":{"docname":"howto/custom-model-fields","title":"Jak utworzyć własne modele pól","url":"/pl/4.2/howto/custom-model-fields/"},"formats":{"html":"/pl/4.2/howto/custom-management-commands/","markdown":"/pl/4.2/howto/custom-management-commands.md","json":"/pl/4.2/howto/custom-management-commands.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/howto/custom-management-commands.txt","official":"https://docs.djangoproject.com/pl/4.2/howto/custom-management-commands/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}