{"title":"Applications","version":"3.2","locale":"en","docname":"ref/applications","url":"/en/3.2/ref/applications/","canonical":"https://djangodocs.dev/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.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</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, create an <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> module inside the\napplication, then define a subclass 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> there.</p>\n<p>When <a class=\"reference internal\" href=\"/en/3.2/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, by default, if Django finds exactly one <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\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> submodule, it uses that configuration for the application. This\nbehavior may be disabled by setting <a class=\"reference internal\" href=\"#django.apps.AppConfig.default\" title=\"django.apps.AppConfig.default\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">AppConfig.default</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n<p>If the <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> module contains more than one <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,\nDjango will look for a single one where <a class=\"reference internal\" href=\"#django.apps.AppConfig.default\" title=\"django.apps.AppConfig.default\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">AppConfig.default</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>.</p>\n<p>If no <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 is found, the base <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\nwill be used.</p>\n<p>Alternatively, <a class=\"reference internal\" href=\"/en/3.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> may contain the dotted path to a\nconfiguration class to specify it explicitly:</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=\"n\">INSTALLED_APPS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"o\">...</span>\n    <span class=\"s1\">&#39;polls.apps.PollsAppConfig&#39;</span><span class=\"p\">,</span>\n    <span class=\"o\">...</span>\n<span class=\"p\">]</span>\n</code></pre></div>\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><code class=\"docutils literal notranslate\"><span class=\"pre\">RockNRollConfig</span></code> will be loaded automatically when <a class=\"reference internal\" href=\"/en/3.2/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>. If you need to prevent this, set\n<a class=\"reference internal\" href=\"#django.apps.AppConfig.default\" title=\"django.apps.AppConfig.default\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">default</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> in the class definition.</p>\n<p>You can provide several <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.\nTo tell Django which one to use by default, set <a class=\"reference internal\" href=\"#django.apps.AppConfig.default\" title=\"django.apps.AppConfig.default\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">default</span></code></a> to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> in its definition. If your users want to pick a non-default\nconfiguration, they must replace <code class=\"docutils literal notranslate\"><span class=\"pre\">'rock_n_roll'</span></code> with the dotted path to that\nspecific class in their <a class=\"reference internal\" href=\"/en/3.2/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 <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\">AppConfig.name</span></code></a> attribute tells Django which application this\nconfiguration applies to. You can define any other attribute documented in the\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> API reference.</p>\n<p><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 may be defined anywhere. The <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code>\nconvention merely allows Django to load them automatically when\n<a class=\"reference internal\" href=\"/en/3.2/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 path to an application module rather\nthan the path to a configuration class.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</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<aside class=\"version-note version-changed\" data-version=\"3.2\">\n<p class=\"version-note-title\">Changed in Django 3.2</p><p>In previous versions, a <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> variable in the application\nmodule was used to identify the default application configuration class.</p>\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>This example shows project-specific configuration classes located in a\nsubmodule called <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code>. This is a convention, not a requirement.\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 may be defined anywhere.</p>\n<p>In this situation, <a class=\"reference internal\" href=\"/en/3.2/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> must contain the dotted path to\nthe configuration class because it lives outside of an application and thus\ncannot be automatically detected.</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<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.default\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">default</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.default\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"3.2\">\n<p class=\"version-note-title\">New in Django 3.2</p></aside>\n<p>Set this attribute to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code> to prevent Django from selecting a\nconfiguration class automatically. This is useful when <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> defines\nonly one <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 but you don’t want Django to use it by\ndefault.</p>\n<p>Set this attribute to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> to tell Django to select a configuration\nclass automatically. This is useful when <code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> defines more than one\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 and you want Django to use one of them by\ndefault.</p>\n<p>By default, this attribute isn’t set.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.apps.AppConfig.default_auto_field\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">AppConfig.</span></span><span class=\"sig-name descname\"><span class=\"pre\">default_auto_field</span></span><a class=\"heading-anchor\" href=\"#django.apps.AppConfig.default_auto_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"3.2\">\n<p class=\"version-note-title\">New in Django 3.2</p></aside>\n<p>The implicit primary key type to add to models within this app. You can\nuse this to keep <a class=\"reference internal\" href=\"/en/3.2/ref/models/fields/#django.db.models.AutoField\" title=\"django.db.models.AutoField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AutoField</span></code></a> as the primary key\ntype for third party applications.</p>\n<p>By default, this is the value of <a class=\"reference internal\" href=\"/en/3.2/ref/settings/#std-setting-DEFAULT_AUTO_FIELD\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEFAULT_AUTO_FIELD</span></code></a>.</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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"(in 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=\"/en/3.2/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\">Warning</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=\"/en/3.2/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=\"/en/3.2/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\">Note</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=\"/en/3.2/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=\"(in 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=\"/en/3.2/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=\"(in 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=\"(in 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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.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<ol class=\"arabic\">\n<li><p>First Django imports each item in <a class=\"reference internal\" href=\"/en/3.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>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 looks for an application configuration in an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">apps.py</span></code> submodule, or else 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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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=\"/en/3.2/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":"/en/3.2/ref/"}],"prev":{"docname":"ref/index","title":"API Reference","url":"/en/3.2/ref/"},"next":{"docname":"ref/checks","title":"System check framework","url":"/en/3.2/ref/checks/"},"formats":{"html":"/en/3.2/ref/applications/","markdown":"/en/3.2/ref/applications.md","json":"/en/3.2/ref/applications.json"},"source":"https://github.com/django/django/blob/stable/3.2.x/docs/ref/applications.txt","official":"https://docs.djangoproject.com/en/3.2/ref/applications/","inVersions":["dev","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","1.9","1.8"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}