{"title":"Applications","version":"3.1","locale":"pl","docname":"ref/applications","url":"/pl/3.1/ref/applications/","canonical":"https://djangodocs.dev/pl/3.1/ref/applications/","summary":"Django contains a registry of installed applications that stores configuration and provides introspection. It also maintains a list of available models . This…","html":"<span id=\"applications\"></span><h1>Applications<a class=\"heading-anchor\" href=\"#module-django.apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django contains a registry of installed applications that stores configuration\nand provides introspection. It also maintains a list of available <a class=\"reference internal\" href=\"/pl/3.1/topics/db/models/\"><span class=\"doc\">models</span></a>.</p>\n<p>This registry is called <a class=\"reference internal\" href=\"#django.apps.apps\" title=\"django.apps.apps\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">apps</span></code></a> and it’s available in\n<a class=\"reference internal\" href=\"#module-django.apps\" title=\"django.apps\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.apps</span></code></a>:</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=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">apps</span>\n<span class=\"gp\">&gt;&gt;&gt; </span><span class=\"n\">apps</span><span class=\"o\">.</span><span class=\"n\">get_app_config</span><span class=\"p\">(</span><span class=\"s1\">&#39;admin&#39;</span><span class=\"p\">)</span><span class=\"o\">.</span><span class=\"n\">verbose_name</span>\n<span class=\"go\">&#39;Administration&#39;</span>\n</code></pre></div>\n<section id=\"projects-and-applications\">\n<h2>Projects and applications<a class=\"heading-anchor\" href=\"#projects-and-applications\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The term <strong>project</strong> describes a Django web application. The project Python\npackage is defined primarily by a settings module, but it usually contains\nother things. For example, when you run  <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span> <span class=\"pre\">mysite</span></code>\nyou’ll get a <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> project directory that contains a <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> Python\npackage with <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">urls.py</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">asgi.py</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">wsgi.py</span></code>. The\nproject package is often extended to include things like fixtures, CSS, and\ntemplates which aren’t tied to a particular application.</p>\n<p>A <strong>project’s root directory</strong> (the one that contains <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code>) is usually\nthe container for all of a project’s applications which aren’t installed\nseparately.</p>\n<p>The term <strong>application</strong> describes a Python package that provides some set of\nfeatures. Applications <a class=\"reference internal\" href=\"/pl/3.1/intro/reusable-apps/\"><span class=\"doc\">may be reused</span></a> in various\nprojects.</p>\n<p>Applications include some combination of models, views, templates, template\ntags, static files, URLs, middleware, etc. They’re generally wired into\nprojects with the <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> setting and optionally with other\nmechanisms such as URLconfs, the <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> setting, or template\ninheritance.</p>\n<p>It is important to understand that a Django application is a set of code\nthat interacts with various parts of the framework. There’s no such thing as\nan <code class=\"docutils literal notranslate\"><span class=\"pre\">Application</span></code> object. However, there’s a few places where Django needs to\ninteract with installed applications, mainly for configuration and also for\nintrospection. That’s why the application registry maintains metadata in an\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instance for each installed application.</p>\n<p>There’s no restriction that a project package can’t also be considered an\napplication and have models, etc. (which would require adding it to\n<a class=\"reference internal\" href=\"/pl/3.1/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</section>\n<section id=\"configuring-applications\">\n<span id=\"configuring-applications-ref\"></span><h2>Configuring applications<a class=\"heading-anchor\" href=\"#configuring-applications\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>To configure an application, subclass <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> and put\nthe dotted path to that subclass in <a class=\"reference internal\" href=\"/pl/3.1/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>When <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> contains the dotted path to an application\nmodule, Django checks for a <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> variable in that module.</p>\n<p>If it’s defined, it’s the dotted path to the <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a>\nsubclass for that application.</p>\n<p>If there is no <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code>, Django uses the base\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> class.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> allows applications that predate Django 1.7 such as\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.admin</span></code> to opt-in to <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> features\nwithout requiring users to update their <a class=\"reference internal\" href=\"/pl/3.1/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>New applications should avoid <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code>. Instead they should\nrequire the dotted path to the appropriate <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a>\nsubclass to be configured explicitly in <a class=\"reference internal\" href=\"/pl/3.1/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<section id=\"for-application-authors\">\n<h3>For application authors<a class=\"heading-anchor\" href=\"#for-application-authors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’re creating a pluggable app called „Rock ’n’ roll”, here’s how you\nwould provide a proper name for the admin:</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=\"c1\"># rock_n_roll/apps.py</span>\n\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">AppConfig</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">RockNRollConfig</span><span class=\"p\">(</span><span class=\"n\">AppConfig</span><span class=\"p\">):</span>\n    <span class=\"n\">name</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;rock_n_roll&#39;</span>\n    <span class=\"n\">verbose_name</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Rock ’n’ roll&quot;</span>\n</code></pre></div>\n<p>You can make your application load this <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a>\nsubclass by default as follows:</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=\"c1\"># rock_n_roll/__init__.py</span>\n\n<span class=\"n\">default_app_config</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;rock_n_roll.apps.RockNRollConfig&#39;</span>\n</code></pre></div>\n<p>That will cause <code class=\"docutils literal notranslate\"><span class=\"pre\">RockNRollConfig</span></code> to be used when <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>\ncontains <code class=\"docutils literal notranslate\"><span class=\"pre\">'rock_n_roll'</span></code>. This allows you to make use of\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> features without requiring your users to update\ntheir <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> setting. Besides this use case, it’s best to\navoid using <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> and instead specify the app config class in\n<a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> as described next.</p>\n<p>You can also tell your users to put <code class=\"docutils literal notranslate\"><span class=\"pre\">'rock_n_roll.apps.RockNRollConfig'</span></code> in\ntheir <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> setting. You can even provide several different\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> subclasses with different behaviors and allow\nyour users to choose one via their <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> setting.</p>\n<p>The recommended convention is to put the configuration class in a submodule of\nthe application called <code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code>. However, this isn’t enforced by Django.</p>\n<p>You must include the <a class=\"reference internal\" href=\"#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">name</span></code></a> attribute for Django\nto determine which application this configuration applies to. You can define\nany attributes documented in the <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> API\nreference.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>If your code imports the application registry in an application’s\n<code class=\"docutils literal notranslate\"><span class=\"pre\">__init__.py</span></code>, the name <code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code> will clash with the <code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code> submodule.\nThe best practice is to move that code to a submodule and import it. A\nworkaround is to import the registry under a different name:</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.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">apps</span> <span class=\"k\">as</span> <span class=\"n\">django_apps</span>\n</code></pre></div>\n</aside>\n</section>\n<section id=\"for-application-users\">\n<h3>For application users<a class=\"heading-anchor\" href=\"#for-application-users\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’re using „Rock ’n’ roll” in a project called <code class=\"docutils literal notranslate\"><span class=\"pre\">anthology</span></code>, but you\nwant it to show up as „Jazz Manouche” instead, you can provide your own\nconfiguration:</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=\"c1\"># anthology/apps.py</span>\n\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">rock_n_roll.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">RockNRollConfig</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">JazzManoucheConfig</span><span class=\"p\">(</span><span class=\"n\">RockNRollConfig</span><span class=\"p\">):</span>\n    <span class=\"n\">verbose_name</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;Jazz Manouche&quot;</span>\n\n<span class=\"c1\"># anthology/settings.py</span>\n\n<span class=\"n\">INSTALLED_APPS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s1\">&#39;anthology.apps.JazzManoucheConfig&#39;</span><span class=\"p\">,</span>\n    <span class=\"c1\"># ...</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Again, defining project-specific configuration classes in a submodule called\n<code class=\"docutils literal notranslate\"><span class=\"pre\">apps</span></code> is a convention, not a requirement.</p>\n</section>\n</section>\n<section id=\"application-configuration\">\n<h2>Application configuration<a class=\"heading-anchor\" href=\"#application-configuration\"><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.apps.AppConfig\">\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\">AppConfig</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Application configuration objects store metadata for an application. Some\nattributes can be configured in <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a>\nsubclasses. Others are set by Django and read-only.</p>\n</dd></dl>\n\n<section id=\"configurable-attributes\">\n<h3>Configurable attributes<a class=\"heading-anchor\" href=\"#configurable-attributes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.name\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">name</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Full Python path to the application, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.admin'</span></code>.</p>\n<p>This attribute defines which application the configuration applies to. It\nmust be set in all <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> subclasses.</p>\n<p>It must be unique across a Django project.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.label\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">label</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.label\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Short name for the application, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">'admin'</span></code></p>\n<p>This attribute allows relabeling an application when two applications\nhave conflicting labels. It defaults to the last component of <code class=\"docutils literal notranslate\"><span class=\"pre\">name</span></code>.\nIt should be a valid Python identifier.</p>\n<p>It must be unique across a Django project.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.verbose_name\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">verbose_name</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.verbose_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Human-readable name for the application, e.g. „Administration”.</p>\n<p>This attribute defaults to <code class=\"docutils literal notranslate\"><span class=\"pre\">label.title()</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.path\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">path</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.path\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Filesystem path to the application directory, e.g.\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'/usr/lib/pythonX.Y/dist-packages/django/contrib/admin'</span></code>.</p>\n<p>In most cases, Django can automatically detect and set this, but you can\nalso provide an explicit override as a class attribute on your\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> subclass. In a few situations this is\nrequired; for instance if the app package is a <a class=\"reference internal\" href=\"#namespace-package\">namespace package</a> with\nmultiple paths.</p>\n</dd></dl>\n\n</section>\n<section id=\"read-only-attributes\">\n<h3>Read-only attributes<a class=\"heading-anchor\" href=\"#read-only-attributes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.module\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">module</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.module\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Root module for the application, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;module</span> <span class=\"pre\">'django.contrib.admin'</span> <span class=\"pre\">from</span>\n<span class=\"pre\">'django/contrib/admin/__init__.py'&gt;</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.models_module\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">models_module</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.models_module\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Module containing the models, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;module</span> <span class=\"pre\">'django.contrib.admin.models'</span>\n<span class=\"pre\">from</span> <span class=\"pre\">'django/contrib/admin/models.py'&gt;</span></code>.</p>\n<p>It may be <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> if the application doesn’t contain a <code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code> module.\nNote that the database related signals such as\n<a class=\"reference internal\" href=\"/pl/3.1/ref/signals/#django.db.models.signals.pre_migrate\" title=\"django.db.models.signals.pre_migrate\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">pre_migrate</span></code></a> and\n<a class=\"reference internal\" href=\"/pl/3.1/ref/signals/#django.db.models.signals.post_migrate\" title=\"django.db.models.signals.post_migrate\"><code class=\"xref py py-data docutils literal notranslate\"><span class=\"pre\">post_migrate</span></code></a>\nare only emitted for applications that have a <code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code> module.</p>\n</dd></dl>\n\n</section>\n<section id=\"methods\">\n<h3>Methods<a class=\"heading-anchor\" href=\"#methods\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.get_models\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_models</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.get_models\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns an iterable of <a class=\"reference internal\" href=\"/pl/3.1/ref/models/instances/#django.db.models.Model\" title=\"django.db.models.Model\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Model</span></code></a> classes for this\napplication.</p>\n<p>Requires the app registry to be fully populated.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.get_model\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_model</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">model_name</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">require_ready</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">True</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.get_model\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the <a class=\"reference internal\" href=\"/pl/3.1/ref/models/instances/#django.db.models.Model\" title=\"django.db.models.Model\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Model</span></code></a> with the given\n<code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code>. <code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code> is case-insensitive.</p>\n<p>Raises <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#LookupError\" title=\"(w Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">LookupError</span></code></a> if no such model exists in this application.</p>\n<p>Requires the app registry to be fully populated unless the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> argument is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>. <code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> behaves\nexactly as in <a class=\"reference internal\" href=\"#django.apps.apps.get_model\" title=\"django.apps.apps.get_model\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">apps.get_model()</span></code></a>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.ready\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">ready</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.ready\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Subclasses can override this method to perform initialization tasks such\nas registering signals. It is called as soon as the registry is fully\npopulated.</p>\n<p>Although you can’t import models at the module-level where\n<a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> classes are defined, you can import them in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">ready()</span></code>, using either an <code class=\"docutils literal notranslate\"><span class=\"pre\">import</span></code> statement or\n<a class=\"reference internal\" href=\"#django.apps.AppConfig.get_model\" title=\"django.apps.AppConfig.get_model\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_model()</span></code></a>.</p>\n<p>If you’re registering <a class=\"reference internal\" href=\"/pl/3.1/ref/signals/#module-django.db.models.signals\" title=\"django.db.models.signals: Signals sent by the model system.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">model</span> <span class=\"pre\">signals</span></code></a>, you\ncan refer to the sender by its string label instead of using the model\nclass itself.</p>\n<p>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=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.apps</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">AppConfig</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.db.models.signals</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">pre_save</span>\n\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">RockNRollConfig</span><span class=\"p\">(</span><span class=\"n\">AppConfig</span><span class=\"p\">):</span>\n    <span class=\"c1\"># ...</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">ready</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"c1\"># importing model classes</span>\n        <span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">.models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">MyModel</span>  <span class=\"c1\"># or...</span>\n        <span class=\"n\">MyModel</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">get_model</span><span class=\"p\">(</span><span class=\"s1\">&#39;MyModel&#39;</span><span class=\"p\">)</span>\n\n        <span class=\"c1\"># registering signals with the model&#39;s string label</span>\n        <span class=\"n\">pre_save</span><span class=\"o\">.</span><span class=\"n\">connect</span><span class=\"p\">(</span><span class=\"n\">receiver</span><span class=\"p\">,</span> <span class=\"n\">sender</span><span class=\"o\">=</span><span class=\"s1\">&#39;app_label.MyModel&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Ostrzeżenie</p>\n<p>Although you can access model classes as described above, avoid\ninteracting with the database in your <a class=\"reference internal\" href=\"#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">ready()</span></code></a> implementation.\nThis includes model methods that execute queries\n(<a class=\"reference internal\" href=\"/pl/3.1/ref/models/instances/#django.db.models.Model.save\" title=\"django.db.models.Model.save\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">save()</span></code></a>,\n<a class=\"reference internal\" href=\"/pl/3.1/ref/models/instances/#django.db.models.Model.delete\" title=\"django.db.models.Model.delete\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">delete()</span></code></a>, manager methods etc.), and\nalso raw SQL queries via <code class=\"docutils literal notranslate\"><span class=\"pre\">django.db.connection</span></code>. Your\n<a class=\"reference internal\" href=\"#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">ready()</span></code></a> method will run during startup of every management\ncommand. For example, even though the test database configuration is\nseparate from the production settings, <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">test</span></code> would still\nexecute some queries against your <strong>production</strong> database!</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Informacja</p>\n<p>In the usual initialization process, the <code class=\"docutils literal notranslate\"><span class=\"pre\">ready</span></code> method is only called\nonce by Django. But in some corner cases, particularly in tests which\nare fiddling with installed applications, <code class=\"docutils literal notranslate\"><span class=\"pre\">ready</span></code> might be called more\nthan once. In that case, either write idempotent methods, or put a flag\non your <code class=\"docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code> classes to prevent re-running code which should\nbe executed exactly one time.</p>\n</aside>\n</dd></dl>\n\n</section>\n<section id=\"namespace-packages-as-apps\">\n<span id=\"namespace-package\"></span><h3>Namespace packages as apps<a class=\"heading-anchor\" href=\"#namespace-packages-as-apps\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Python packages without an <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__.py</span></code> file are known as „namespace\npackages” and may be spread across multiple directories at different locations\non <code class=\"docutils literal notranslate\"><span class=\"pre\">sys.path</span></code> (see <span class=\"target\" id=\"index-0\"></span><a class=\"pep reference external\" href=\"https://peps.python.org/pep-0420/\"><strong>PEP 420</strong></a>).</p>\n<p>Django applications require a single base filesystem path where Django\n(depending on configuration) will search for templates, static assets,\netc. Thus, namespace packages may only be Django applications if one of the\nfollowing is true:</p>\n<ol class=\"arabic simple\">\n<li><p>The namespace package actually has only a single location (i.e. is not\nspread across more than one directory.)</p></li>\n<li><p>The <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> class used to configure the application\nhas a <a class=\"reference internal\" href=\"#django.apps.AppConfig.path\" title=\"django.apps.AppConfig.path\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">path</span></code></a> class attribute, which is the\nabsolute directory path Django will use as the single base path for the\napplication.</p></li>\n</ol>\n<p>If neither of these conditions is met, Django will raise\n<a class=\"reference internal\" href=\"/pl/3.1/ref/exceptions/#django.core.exceptions.ImproperlyConfigured\" title=\"django.core.exceptions.ImproperlyConfigured\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">ImproperlyConfigured</span></code></a>.</p>\n</section>\n</section>\n<section id=\"application-registry\">\n<h2>Application registry<a class=\"heading-anchor\" href=\"#application-registry\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps\">\n<span class=\"sig-name descname\"><span class=\"pre\">apps</span></span><a class=\"heading-anchor\" href=\"#django.apps.apps\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The application registry provides the following public API. Methods that\naren’t listed below are considered private and may change without notice.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps.ready\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">apps.</span></span><span class=\"sig-name descname\"><span class=\"pre\">ready</span></span><a class=\"heading-anchor\" href=\"#django.apps.apps.ready\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Boolean attribute that is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> after the registry is fully\npopulated and all <a class=\"reference internal\" href=\"#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">AppConfig.ready()</span></code></a> methods are called.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps.get_app_configs\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">apps.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_app_configs</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.apps.get_app_configs\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns an iterable of <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> instances.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps.get_app_config\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">apps.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_app_config</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_label</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.apps.get_app_config\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns an <a class=\"reference internal\" href=\"#django.apps.AppConfig\" title=\"django.apps.AppConfig\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppConfig</span></code></a> for the application with the\ngiven <code class=\"docutils literal notranslate\"><span class=\"pre\">app_label</span></code>. Raises <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#LookupError\" title=\"(w Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">LookupError</span></code></a> if no such application\nexists.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps.is_installed\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">apps.</span></span><span class=\"sig-name descname\"><span class=\"pre\">is_installed</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_name</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.apps.is_installed\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Checks whether an application with the given name exists in the registry.\n<code class=\"docutils literal notranslate\"><span class=\"pre\">app_name</span></code> is the full name of the app, e.g. <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.admin'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.apps.apps.get_model\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">apps.</span></span><span class=\"sig-name descname\"><span class=\"pre\">get_model</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_label</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">model_name</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">require_ready</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">True</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.apps.apps.get_model\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the <a class=\"reference internal\" href=\"/pl/3.1/ref/models/instances/#django.db.models.Model\" title=\"django.db.models.Model\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Model</span></code></a> with the given <code class=\"docutils literal notranslate\"><span class=\"pre\">app_label</span></code>\nand <code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code>. As a shortcut, this method also accepts a single\nargument in the form <code class=\"docutils literal notranslate\"><span class=\"pre\">app_label.model_name</span></code>. <code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code> is\ncase-insensitive.</p>\n<p>Raises <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#LookupError\" title=\"(w Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">LookupError</span></code></a> if no such application or model exists. Raises\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#ValueError\" title=\"(w Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">ValueError</span></code></a> when called with a single argument that doesn’t contain\nexactly one dot.</p>\n<p>Requires the app registry to be fully populated unless the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> argument is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n<p>Setting <code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> allows looking up models\n<a class=\"reference internal\" href=\"#app-loading-process\"><span class=\"std std-ref\">while the app registry is being populated</span></a>,\nspecifically during the second phase where it imports models. Then\n<code class=\"docutils literal notranslate\"><span class=\"pre\">get_model()</span></code> has the same effect as importing the model. The main use\ncase is to configure model classes with settings, such as\n<a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-AUTH_USER_MODEL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">AUTH_USER_MODEL</span></code></a>.</p>\n<p>When <code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">get_model()</span></code> returns a model class\nthat may not be fully functional (reverse accessors may be missing, for\nexample) until the app registry is fully populated. For this reason, it’s\nbest to leave <code class=\"docutils literal notranslate\"><span class=\"pre\">require_ready</span></code> to the default value of <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> whenever\npossible.</p>\n</dd></dl>\n\n</section>\n<section id=\"initialization-process\">\n<span id=\"app-loading-process\"></span><h2>Initialization process<a class=\"heading-anchor\" href=\"#initialization-process\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<section id=\"how-applications-are-loaded\">\n<h3>How applications are loaded<a class=\"heading-anchor\" href=\"#how-applications-are-loaded\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When Django starts, <a class=\"reference internal\" href=\"#django.setup\" title=\"django.setup\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code></a> is responsible for populating the\napplication registry.</p>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.setup\">\n<span class=\"sig-name descname\"><span class=\"pre\">setup</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">set_prefix</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">True</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.setup\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Configures Django by:</p>\n<ul class=\"simple\">\n<li><p>Loading the settings.</p></li>\n<li><p>Setting up logging.</p></li>\n<li><p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">set_prefix</span></code> is True, setting the URL resolver script prefix to\n<a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-FORCE_SCRIPT_NAME\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORCE_SCRIPT_NAME</span></code></a> if defined, or <code class=\"docutils literal notranslate\"><span class=\"pre\">/</span></code> otherwise.</p></li>\n<li><p>Initializing the application registry.</p></li>\n</ul>\n<p>This function is called automatically:</p>\n<ul class=\"simple\">\n<li><p>When running an HTTP server via Django’s WSGI support.</p></li>\n<li><p>When invoking a management command.</p></li>\n</ul>\n<p>It must be called explicitly in other cases, for instance in plain Python\nscripts.</p>\n</dd></dl>\n\n<p>The application registry is initialized in three stages. At each stage, Django\nprocesses all applications in the order of <a class=\"reference internal\" href=\"/pl/3.1/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<ol class=\"arabic\">\n<li><p>First Django imports each item in <a class=\"reference internal\" href=\"/pl/3.1/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>If it’s an application configuration class, Django imports the root package\nof the application, defined by its <a class=\"reference internal\" href=\"#django.apps.AppConfig.name\" title=\"django.apps.AppConfig.name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">name</span></code></a> attribute. If\nit’s a Python package, Django creates a default application configuration.</p>\n<p><em>At this stage, your code shouldn’t import any models!</em></p>\n<p>In other words, your applications» root packages and the modules that\ndefine your application configuration classes shouldn’t import any models,\neven indirectly.</p>\n<p>Strictly speaking, Django allows importing models once their application\nconfiguration is loaded. However, in order to avoid needless constraints on\nthe order of <a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>, it’s strongly recommended not\nimport any models at this stage.</p>\n<p>Once this stage completes, APIs that operate on application configurations\nsuch as <a class=\"reference internal\" href=\"#django.apps.apps.get_app_config\" title=\"django.apps.apps.get_app_config\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_app_config()</span></code></a> become usable.</p>\n</li>\n<li><p>Then Django attempts to import the <code class=\"docutils literal notranslate\"><span class=\"pre\">models</span></code> submodule of each application,\nif there is one.</p>\n<p>You must define or import all models in your application’s <code class=\"docutils literal notranslate\"><span class=\"pre\">models.py</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">models/__init__.py</span></code>. Otherwise, the application registry may not be fully\npopulated at this point, which could cause the ORM to malfunction.</p>\n<p>Once this stage completes, APIs that operate on models such as\n<a class=\"reference internal\" href=\"#django.apps.apps.get_model\" title=\"django.apps.apps.get_model\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_model()</span></code></a> become usable.</p>\n</li>\n<li><p>Finally Django runs the <a class=\"reference internal\" href=\"#django.apps.AppConfig.ready\" title=\"django.apps.AppConfig.ready\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">ready()</span></code></a> method of each application\nconfiguration.</p></li>\n</ol>\n</section>\n<section id=\"troubleshooting\">\n<span id=\"applications-troubleshooting\"></span><h3>Troubleshooting<a class=\"heading-anchor\" href=\"#troubleshooting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Here are some common problems that you may encounter during initialization:</p>\n<ul>\n<li><p><a class=\"reference internal\" href=\"/pl/3.1/ref/exceptions/#django.core.exceptions.AppRegistryNotReady\" title=\"django.core.exceptions.AppRegistryNotReady\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AppRegistryNotReady</span></code></a>: This happens when\nimporting an application configuration or a models module triggers code that\ndepends on the app registry.</p>\n<p>For example, <a class=\"reference internal\" href=\"/pl/3.1/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gettext()</span></code></a> uses the app\nregistry to look up translation catalogs in applications. To translate at\nimport time, you need <a class=\"reference internal\" href=\"/pl/3.1/ref/utils/#django.utils.translation.gettext_lazy\" title=\"django.utils.translation.gettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gettext_lazy()</span></code></a>\ninstead. (Using <a class=\"reference internal\" href=\"/pl/3.1/ref/utils/#django.utils.translation.gettext\" title=\"django.utils.translation.gettext\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">gettext()</span></code></a> would be a bug,\nbecause the translation would happen at import time, rather than at each\nrequest depending on the active language.)</p>\n<p>Executing database queries with the ORM at import time in models modules\nwill also trigger this exception. The ORM cannot function properly until all\nmodels are available.</p>\n<p>This exception also happens if you forget to call <a class=\"reference internal\" href=\"#django.setup\" title=\"django.setup\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code></a> in\na standalone Python script.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">ImportError:</span> <span class=\"pre\">cannot</span> <span class=\"pre\">import</span> <span class=\"pre\">name</span> <span class=\"pre\">...</span></code> This happens if the import sequence\nends up in a loop.</p>\n<p>To eliminate such problems, you should minimize dependencies between your\nmodels modules and do as little work as possible at import time. To avoid\nexecuting code at import time, you can move it into a function and cache its\nresults. The code will be executed when you first need its results. This\nconcept is known as „lazy evaluation”.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.admin</span></code> automatically performs autodiscovery of <code class=\"docutils literal notranslate\"><span class=\"pre\">admin</span></code>\nmodules in installed applications. To prevent it, change your\n<a class=\"reference internal\" href=\"/pl/3.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> to contain\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.admin.apps.SimpleAdminConfig'</span></code> instead of\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.admin'</span></code>.</p></li>\n</ul>\n</section>\n</section>","rootId":"module-django.apps","toc":[{"title":"Projects and applications","anchor":"projects-and-applications","children":[]},{"title":"Configuring applications","anchor":"configuring-applications","children":[{"title":"For application authors","anchor":"for-application-authors","children":[]},{"title":"For application users","anchor":"for-application-users","children":[]}]},{"title":"Application configuration","anchor":"application-configuration","children":[{"title":"Configurable attributes","anchor":"configurable-attributes","children":[]},{"title":"Read-only attributes","anchor":"read-only-attributes","children":[]},{"title":"Methods","anchor":"methods","children":[]},{"title":"Namespace packages as apps","anchor":"namespace-packages-as-apps","children":[]}]},{"title":"Application registry","anchor":"application-registry","children":[]},{"title":"Initialization process","anchor":"initialization-process","children":[{"title":"How applications are loaded","anchor":"how-applications-are-loaded","children":[]},{"title":"Troubleshooting","anchor":"troubleshooting","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/pl/3.1/ref/"}],"prev":{"docname":"ref/index","title":"API Reference","url":"/pl/3.1/ref/"},"next":{"docname":"ref/checks","title":"System check framework","url":"/pl/3.1/ref/checks/"},"formats":{"html":"/pl/3.1/ref/applications/","markdown":"/pl/3.1/ref/applications.md","json":"/pl/3.1/ref/applications.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/ref/applications.txt","official":"https://docs.djangoproject.com/pl/3.1/ref/applications/","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","pt-br","ko","es","el","pl"]}