{"title":"アプリケーション","version":"1.10","locale":"ja","docname":"ref/applications","url":"/ja/1.10/ref/applications/","canonical":"https://djangodocs.dev/ja/1.10/ref/applications/","summary":"Django には、設定の保存と調査の手段を提供するインストール済みアプリケーションのレジストリがあり、利用可能な モデル のリストもアクセスできます。 このレジストリは単に apps と呼ばれ、次のようにして django.apps から使用できます。 Code Copy >>> from django.apps…","html":"<span id=\"applications\"></span><h1>アプリケーション<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 には、設定の保存と調査の手段を提供するインストール済みアプリケーションのレジストリがあり、利用可能な <a class=\"reference internal\" href=\"/ja/1.10/topics/db/models/\"><span class=\"doc\">モデル</span></a> のリストもアクセスできます。</p>\n<p>このレジストリは単に <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> と呼ばれ、次のようにして <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;Admin&#39;</span>\n</code></pre></div>\n<section id=\"projects-and-applications\">\n<h2>プロジェクトとアプリケーション<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><strong>プロジェクト (project)</strong> という単語は、Django の web アプリケーションを指します。プロジェクトの Python パッケージは主に settings モジュールで定義されますが、通常は他のファイルも含まれます。たとえば、 <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">startproject</span> <span class=\"pre\">mysite</span></code> を実行すると、<code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> プロジェクトディレクトリが作成され、その中には <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\">wsgi.py</span></code> などのファイルが含まれる <code class=\"docutils literal notranslate\"><span class=\"pre\">mysite</span></code> Python パッケージが作られます。プロジェクトパッケージは、fixture や CSS、テンプレートなど特定のアプリケーションに束縛されないファイルも含まれることがふつうです。</p>\n<p><strong>プロジェクトのルートディレクトリ</strong> (<code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> があるディレクトリ) は、プロジェクトと一緒にインストールされるすべてのアプリケーションのコンテナとして機能します。</p>\n<p><strong>アプリケーション (application)</strong> という言葉は、いくつかの機能を提供する Python パッケージを意味します。アプリケーションはさまざまなプロジェクトで <a class=\"reference internal\" href=\"/ja/1.10/intro/reusable-apps/\"><span class=\"doc\">再利用する</span></a> ことができます。</p>\n<p>アプリケーションには、モデル、ビュー、テンプレート、テンプレートタグ、スタティックファイル、ミドルウェアなどが含まれます。これらは一般に <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> 設定で有効になり、それ以外では URLconfs、 <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> 設定、テンプレート継承などの仕組みから使われます。</p>\n<p>Django のアプリケーションは、フレームワークのさまざまなパーツとやりとりをする単なるコードの集まりであると理解するのは大切です。<code class=\"docutils literal notranslate\"><span class=\"pre\">Application</span></code> オブジェクトのようなものは存在しません。しかしながら、Django がインストール済みのアプリケーションの主に設定やイントロスペクションとやりとりをする必要があることもあります。そのため、インストールアプリケーションごとのメタデータは、アプリケーションレジストリが <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> インスタンス内に保存しています。</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=\"/ja/1.10/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>アプリケーションを設定する<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>アプリケーションを設定するには、 <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> のサブクラスを作り、そのサブクラスへのドット区切りのパスを <a class=\"reference internal\" href=\"/ja/1.10/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><a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> にアプリケーションモジュールを指すドット区切りのパスがある場合、Django はそのモジュールの <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> 変数をチェックします。</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> サブクラスになります。</p>\n<p>もし <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> が定義されていなければ、Django は ベースとなる <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> クラスを使用します。</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=\"/ja/1.10/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=\"/ja/1.10/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 &quot;Rock ’n’ roll&quot;, 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=\"/ja/1.10/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>\njust contains <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\nupdate their <a class=\"reference internal\" href=\"/ja/1.10/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\nbest to avoid using <code class=\"docutils literal notranslate\"><span class=\"pre\">default_app_config</span></code> and instead specify the app config\nclass in <a class=\"reference internal\" href=\"/ja/1.10/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>Of course, you can also tell your users to put\n<code class=\"docutils literal notranslate\"><span class=\"pre\">'rock_n_roll.apps.RockNRollConfig'</span></code> in their <a class=\"reference internal\" href=\"/ja/1.10/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a>\nsetting. 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=\"/ja/1.10/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\">注釈</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>アプリケーションユーザー向け<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 &quot;Rock ’n’ roll&quot; in a project called <code class=\"docutils literal notranslate\"><span class=\"pre\">anthology</span></code>, but you\nwant it to show up as &quot;Jazz Manouche&quot; 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>Djangoプロジェクト全体の中で固有である必要があります。</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>Djangoプロジェクト全体の中で固有である必要があります。</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. &quot;Administration&quot;.</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/python3.4/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>読み取り専用属性<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__.pyc'&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.pyc'&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=\"/ja/1.10/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=\"/ja/1.10/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>メソッド<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=\"/ja/1.10/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</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><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=\"/ja/1.10/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>. 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\napplication. <code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code> is case-insensitive.</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=\"/ja/1.10/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>実装例:</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.db.models.signals</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">pre_save</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\">警告</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=\"/ja/1.10/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=\"/ja/1.10/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\">注釈</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-python-3-3\">\n<span id=\"namespace-package\"></span><h3>Namespace packages as apps (Python 3.3+)<a class=\"heading-anchor\" href=\"#namespace-packages-as-apps-python-3-3\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Python versions 3.3 and later support Python packages without an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">__init__.py</span></code> file. These packages are known as &quot;namespace packages&quot; and may\nbe spread across multiple directories at different locations on <code class=\"docutils literal notranslate\"><span class=\"pre\">sys.path</span></code>\n(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=\"/ja/1.10/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><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=\"/ja/1.10/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</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=\"/ja/1.10/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<aside class=\"version-note version-changed\" data-version=\"1.10\">\n<p class=\"version-note-title\">Changed in Django 1.10</p><p>The ability to set the URL resolver script prefix is new.</p>\n</aside>\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=\"/ja/1.10/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=\"/ja/1.10/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=\"/ja/1.10/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>トラブルシューティング<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=\"/ja/1.10/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=\"/ja/1.10/ref/utils/#django.utils.translation.ugettext\" title=\"django.utils.translation.ugettext\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">ugettext()</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=\"/ja/1.10/ref/utils/#django.utils.translation.ugettext_lazy\" title=\"django.utils.translation.ugettext_lazy\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">ugettext_lazy()</span></code></a>\ninstead. (Using <a class=\"reference internal\" href=\"/ja/1.10/ref/utils/#django.utils.translation.ugettext\" title=\"django.utils.translation.ugettext\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">ugettext()</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>Another common culprit is <a class=\"reference internal\" href=\"/ja/1.10/topics/auth/customizing/#django.contrib.auth.get_user_model\" title=\"django.contrib.auth.get_user_model\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.get_user_model()</span></code></a>. Use\nthe <a class=\"reference internal\" href=\"/ja/1.10/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> setting to reference the User model at import\ntime.</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 &quot;lazy evaluation&quot;.</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=\"/ja/1.10/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":"プロジェクトとアプリケーション","anchor":"projects-and-applications","children":[]},{"title":"アプリケーションを設定する","anchor":"configuring-applications","children":[{"title":"For application authors","anchor":"for-application-authors","children":[]},{"title":"アプリケーションユーザー向け","anchor":"for-application-users","children":[]}]},{"title":"Application configuration","anchor":"application-configuration","children":[{"title":"Configurable attributes","anchor":"configurable-attributes","children":[]},{"title":"読み取り専用属性","anchor":"read-only-attributes","children":[]},{"title":"メソッド","anchor":"methods","children":[]},{"title":"Namespace packages as apps (Python 3.3+)","anchor":"namespace-packages-as-apps-python-3-3","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":"トラブルシューティング","anchor":"troubleshooting","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/ja/1.10/ref/"}],"prev":{"docname":"ref/index","title":"API Reference","url":"/ja/1.10/ref/"},"next":{"docname":"ref/checks","title":"System check framework","url":"/ja/1.10/ref/checks/"},"formats":{"html":"/ja/1.10/ref/applications/","markdown":"/ja/1.10/ref/applications.md","json":"/ja/1.10/ref/applications.json"},"source":"https://github.com/django/django/blob/stable/1.10.x/docs/ref/applications.txt","official":"https://docs.djangoproject.com/ja/1.10/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","1.9"],"inLocales":["en","fr","ja","id","pt-br","es","el","pl"]}