{"title":"Django settings","version":"2.0","locale":"ko","docname":"topics/settings","url":"/ko/2.0/topics/settings/","canonical":"https://djangodocs.dev/ko/2.0/topics/settings/","summary":"A Django settings file contains all the configuration of your Django installation. This document explains how settings work and which settings are available. The…","html":"<h1>Django settings<a class=\"heading-anchor\" href=\"#django-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>A Django settings file contains all the configuration of your Django\ninstallation. This document explains how settings work and which settings are\navailable.</p>\n<section id=\"the-basics\">\n<h2>The basics<a class=\"heading-anchor\" href=\"#the-basics\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>A settings file is just a Python module with module-level variables.</p>\n<p>Here are a couple of example settings:</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\">ALLOWED_HOSTS</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;www.example.com&#39;</span><span class=\"p\">]</span>\n<span class=\"n\">DEBUG</span> <span class=\"o\">=</span> <span class=\"kc\">False</span>\n<span class=\"n\">DEFAULT_FROM_EMAIL</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;webmaster@example.com&#39;</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>If you set <a class=\"reference internal\" href=\"/ko/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>, you also need to properly set\nthe <a class=\"reference internal\" href=\"/ko/2.0/ref/settings/#std-setting-ALLOWED_HOSTS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">ALLOWED_HOSTS</span></code></a> setting.</p>\n</aside>\n<p>Because a settings file is a Python module, the following apply:</p>\n<ul>\n<li><p>It doesn’t allow for Python syntax errors.</p></li>\n<li><p>It can assign settings dynamically using normal Python syntax.\nFor 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=\"n\">MY_SETTING</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"nb\">str</span><span class=\"p\">(</span><span class=\"n\">i</span><span class=\"p\">)</span> <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"mi\">30</span><span class=\"p\">)]</span>\n</code></pre></div>\n</li>\n<li><p>It can import values from other settings files.</p></li>\n</ul>\n</section>\n<section id=\"designating-the-settings\">\n<span id=\"django-settings-module\"></span><h2>Designating the settings<a class=\"heading-anchor\" href=\"#designating-the-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"std envvar\">\n<dt class=\"sig sig-object std\" id=\"envvar-DJANGO_SETTINGS_MODULE\">\n<span class=\"sig-name descname\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></span><a class=\"heading-anchor\" href=\"#envvar-DJANGO_SETTINGS_MODULE\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>When you use Django, you have to tell it which settings you’re using. Do this\nby using an environment variable, <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code>.</p>\n<p>The value of <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code> should be in Python path syntax, e.g.\n<code class=\"docutils literal notranslate\"><span class=\"pre\">mysite.settings</span></code>. Note that the settings module should be on the\nPython <a class=\"reference external\" href=\"http://www.diveintopython3.net/your-first-python-program.html#importsearchpath\">import search path</a>.</p>\n<section id=\"the-django-admin-utility\">\n<h3>The <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code> utility<a class=\"heading-anchor\" href=\"#the-django-admin-utility\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>When using <a class=\"reference internal\" href=\"/ko/2.0/ref/django-admin/\"><span class=\"doc\">django-admin</span></a>, you can either set the\nenvironment variable once, or explicitly pass in the settings module each time\nyou run the utility.</p>\n<p>Example (Unix Bash shell):</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\">export</span> <span class=\"n\">DJANGO_SETTINGS_MODULE</span><span class=\"o\">=</span><span class=\"n\">mysite</span><span class=\"o\">.</span><span class=\"n\">settings</span>\n<span class=\"n\">django</span><span class=\"o\">-</span><span class=\"n\">admin</span> <span class=\"n\">runserver</span>\n</code></pre></div>\n<p>Example (Windows shell):</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=\"nb\">set</span> <span class=\"n\">DJANGO_SETTINGS_MODULE</span><span class=\"o\">=</span><span class=\"n\">mysite</span><span class=\"o\">.</span><span class=\"n\">settings</span>\n<span class=\"n\">django</span><span class=\"o\">-</span><span class=\"n\">admin</span> <span class=\"n\">runserver</span>\n</code></pre></div>\n<p>Use the <code class=\"docutils literal notranslate\"><span class=\"pre\">--settings</span></code> command-line argument to specify the settings manually:</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\">django</span><span class=\"o\">-</span><span class=\"n\">admin</span> <span class=\"n\">runserver</span> <span class=\"o\">--</span><span class=\"n\">settings</span><span class=\"o\">=</span><span class=\"n\">mysite</span><span class=\"o\">.</span><span class=\"n\">settings</span>\n</code></pre></div>\n</section>\n<section id=\"on-the-server-mod-wsgi\">\n<h3>On the server (<code class=\"docutils literal notranslate\"><span class=\"pre\">mod_wsgi</span></code>)<a class=\"heading-anchor\" href=\"#on-the-server-mod-wsgi\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>In your live server environment, you’ll need to tell your WSGI\napplication what settings file to use. Do that with <code class=\"docutils literal notranslate\"><span class=\"pre\">os.environ</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">os</span>\n\n<span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">environ</span><span class=\"p\">[</span><span class=\"s1\">&#39;DJANGO_SETTINGS_MODULE&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;mysite.settings&#39;</span>\n</code></pre></div>\n<p>Read the <a class=\"reference internal\" href=\"/ko/2.0/howto/deployment/wsgi/modwsgi/\"><span class=\"doc\">Django mod_wsgi documentation</span></a> for more information and other common\nelements to a Django WSGI application.</p>\n</section>\n</section>\n<section id=\"default-settings\">\n<h2>Default settings<a class=\"heading-anchor\" href=\"#default-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>A Django settings file doesn’t have to define any settings if it doesn’t need\nto. Each setting has a sensible default value. These defaults live in the\nmodule <code class=\"file docutils literal notranslate\"><span class=\"pre\">django/conf/global_settings.py</span></code>.</p>\n<p>Here’s the algorithm Django uses in compiling settings:</p>\n<ul class=\"simple\">\n<li><p>Load settings from <code class=\"docutils literal notranslate\"><span class=\"pre\">global_settings.py</span></code>.</p></li>\n<li><p>Load settings from the specified settings file, overriding the global\nsettings as necessary.</p></li>\n</ul>\n<p>Note that a settings file should <em>not</em> import from <code class=\"docutils literal notranslate\"><span class=\"pre\">global_settings</span></code>, because\nthat’s redundant.</p>\n<section id=\"seeing-which-settings-you-ve-changed\">\n<h3>Seeing which settings you’ve changed<a class=\"heading-anchor\" href=\"#seeing-which-settings-you-ve-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>There’s an easy way to view which of your settings deviate from the default\nsettings. The command <code class=\"docutils literal notranslate\"><span class=\"pre\">python</span> <span class=\"pre\">manage.py</span> <span class=\"pre\">diffsettings</span></code> displays differences\nbetween the current settings file and Django’s default settings.</p>\n<p>For more, see the <a class=\"reference internal\" href=\"/ko/2.0/ref/django-admin/#django-admin-diffsettings\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">diffsettings</span></code></a> documentation.</p>\n</section>\n</section>\n<section id=\"using-settings-in-python-code\">\n<h2>Using settings in Python code<a class=\"heading-anchor\" href=\"#using-settings-in-python-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In your Django apps, use settings by importing the object\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.settings</span></code>. 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.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n\n<span class=\"k\">if</span> <span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">DEBUG</span><span class=\"p\">:</span>\n    <span class=\"c1\"># Do something</span>\n</code></pre></div>\n<p>Note that <code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.settings</span></code> isn’t a module – it’s an object. So\nimporting individual settings is not possible:</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.conf.settings</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">DEBUG</span>  <span class=\"c1\"># This won&#39;t work.</span>\n</code></pre></div>\n<p>Also note that your code should <em>not</em> import from either <code class=\"docutils literal notranslate\"><span class=\"pre\">global_settings</span></code> or\nyour own settings file. <code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.settings</span></code> abstracts the concepts of\ndefault settings and site-specific settings; it presents a single interface.\nIt also decouples the code that uses settings from the location of your\nsettings.</p>\n</section>\n<section id=\"altering-settings-at-runtime\">\n<h2>Altering settings at runtime<a class=\"heading-anchor\" href=\"#altering-settings-at-runtime\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>You shouldn’t alter settings in your applications at runtime. For example,\ndon’t do this in a view:</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.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n\n<span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">DEBUG</span> <span class=\"o\">=</span> <span class=\"kc\">True</span>   <span class=\"c1\"># Don&#39;t do this!</span>\n</code></pre></div>\n<p>The only place you should assign to settings is in a settings file.</p>\n</section>\n<section id=\"security\">\n<h2>Security<a class=\"heading-anchor\" href=\"#security\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Because a settings file contains sensitive information, such as the database\npassword, you should make every attempt to limit access to it. For example,\nchange its file permissions so that only you and your Web server’s user can\nread it. This is especially important in a shared-hosting environment.</p>\n</section>\n<section id=\"available-settings\">\n<h2>Available settings<a class=\"heading-anchor\" href=\"#available-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>For a full list of available settings, see the <a class=\"reference internal\" href=\"/ko/2.0/ref/settings/\"><span class=\"doc\">settings reference</span></a>.</p>\n</section>\n<section id=\"creating-your-own-settings\">\n<h2>Creating your own settings<a class=\"heading-anchor\" href=\"#creating-your-own-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>There’s nothing stopping you from creating your own settings, for your own\nDjango apps. Just follow these guidelines:</p>\n<ul class=\"simple\">\n<li><p>Setting names must be all uppercase.</p></li>\n<li><p>Don’t reinvent an already-existing setting.</p></li>\n</ul>\n<p>For settings that are sequences, Django itself uses lists, but this is only\na convention.</p>\n</section>\n<section id=\"using-settings-without-setting-django-settings-module\">\n<span id=\"settings-without-django-settings-module\"></span><h2>Using settings without setting <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code><a class=\"heading-anchor\" href=\"#using-settings-without-setting-django-settings-module\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In some cases, you might want to bypass the <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code>\nenvironment variable. For example, if you’re using the template system by\nitself, you likely don’t want to have to set up an environment variable\npointing to a settings module.</p>\n<p>In these cases, you can configure Django’s settings manually. Do this by\ncalling:</p>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.conf.settings.configure\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">django.conf.settings.</span></span><span class=\"sig-name descname\"><span class=\"pre\">configure</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">default_settings</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">settings</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.conf.settings.configure\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\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.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n\n<span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">configure</span><span class=\"p\">(</span><span class=\"n\">DEBUG</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Pass <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> as many keyword arguments as you’d like, with each keyword\nargument representing a setting and its value. Each argument name should be all\nuppercase, with the same name as the settings described above. If a particular\nsetting is not passed to <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> and is needed at some later point,\nDjango will use the default setting value.</p>\n<p>Configuring Django in this fashion is mostly necessary – and, indeed,\nrecommended – when you’re using a piece of the framework inside a larger\napplication.</p>\n<p>Consequently, when configured via <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.configure()</span></code>, Django will not\nmake any modifications to the process environment variables (see the\ndocumentation of <a class=\"reference internal\" href=\"/ko/2.0/ref/settings/#std-setting-TIME_ZONE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TIME_ZONE</span></code></a> for why this would normally occur). It’s\nassumed that you’re already in full control of your environment in these\ncases.</p>\n<section id=\"custom-default-settings\">\n<h3>Custom default settings<a class=\"heading-anchor\" href=\"#custom-default-settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’d like default values to come from somewhere other than\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.global_settings</span></code>, you can pass in a module or class that\nprovides the default settings as the <code class=\"docutils literal notranslate\"><span class=\"pre\">default_settings</span></code> argument (or as the\nfirst positional argument) in the call to <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code>.</p>\n<p>In this example, default settings are taken from <code class=\"docutils literal notranslate\"><span class=\"pre\">myapp_defaults</span></code>, and the\n<a class=\"reference internal\" href=\"/ko/2.0/ref/settings/#std-setting-DEBUG\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DEBUG</span></code></a> setting is set to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, regardless of its value in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">myapp_defaults</span></code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">myapp</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">myapp_defaults</span>\n\n<span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">configure</span><span class=\"p\">(</span><span class=\"n\">default_settings</span><span class=\"o\">=</span><span class=\"n\">myapp_defaults</span><span class=\"p\">,</span> <span class=\"n\">DEBUG</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>The following example, which uses <code class=\"docutils literal notranslate\"><span class=\"pre\">myapp_defaults</span></code> as a positional argument,\nis equivalent:</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\">settings</span><span class=\"o\">.</span><span class=\"n\">configure</span><span class=\"p\">(</span><span class=\"n\">myapp_defaults</span><span class=\"p\">,</span> <span class=\"n\">DEBUG</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Normally, you will not need to override the defaults in this fashion. The\nDjango defaults are sufficiently tame that you can safely use them. Be aware\nthat if you do pass in a new default module, it entirely <em>replaces</em> the Django\ndefaults, so you must specify a value for every possible setting that might be\nused in that code you are importing. Check in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.settings.global_settings</span></code> for the full list.</p>\n</section>\n<section id=\"either-configure-or-django-settings-module-is-required\">\n<h3>Either <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code> is required<a class=\"heading-anchor\" href=\"#either-configure-or-django-settings-module-is-required\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’re not setting the <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code> environment variable, you\n<em>must</em> call <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> at some point before using any code that reads\nsettings.</p>\n<p>If you don’t set <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code> and don’t call <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code>,\nDjango will raise an <code class=\"docutils literal notranslate\"><span class=\"pre\">ImportError</span></code> exception the first time a setting\nis accessed.</p>\n<p>If you set <code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code>, access settings values somehow, <em>then</em>\ncall <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code>, Django will raise a <code class=\"docutils literal notranslate\"><span class=\"pre\">RuntimeError</span></code> indicating\nthat settings have already been configured. There is a property just for this\npurpose:</p>\n<p>For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n<span class=\"k\">if</span> <span class=\"ow\">not</span> <span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">configured</span><span class=\"p\">:</span>\n    <span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">configure</span><span class=\"p\">(</span><span class=\"n\">myapp_defaults</span><span class=\"p\">,</span> <span class=\"n\">DEBUG</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Also, it’s an error to call <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> more than once, or to call\n<code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> after any setting has been accessed.</p>\n<p>It boils down to this: Use exactly one of either <code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code> or\n<code class=\"docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code>. Not both, and not neither.</p>\n</section>\n<section id=\"calling-django-setup-is-required-for-standalone-django-usage\">\n<h3>Calling <code class=\"docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code> is required for “standalone” Django usage<a class=\"heading-anchor\" href=\"#calling-django-setup-is-required-for-standalone-django-usage\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you’re using components of Django “standalone” – for example, writing a\nPython script which loads some Django templates and renders them, or uses the\nORM to fetch some data – there’s one more step you’ll need in addition to\nconfiguring settings.</p>\n<p>After you’ve either set <span class=\"target\" id=\"index-0\"></span><a class=\"reference internal\" href=\"#envvar-DJANGO_SETTINGS_MODULE\"><code class=\"xref std std-envvar docutils literal notranslate\"><span class=\"pre\">DJANGO_SETTINGS_MODULE</span></code></a> or called\n<code class=\"docutils literal notranslate\"><span class=\"pre\">configure()</span></code>, you’ll need to call <a class=\"reference internal\" href=\"/ko/2.0/ref/applications/#django.setup\" title=\"django.setup\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code></a> to load your\nsettings and populate Django’s application registry. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">django</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.conf</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">settings</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">myapp</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">myapp_defaults</span>\n\n<span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">configure</span><span class=\"p\">(</span><span class=\"n\">default_settings</span><span class=\"o\">=</span><span class=\"n\">myapp_defaults</span><span class=\"p\">,</span> <span class=\"n\">DEBUG</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n<span class=\"n\">django</span><span class=\"o\">.</span><span class=\"n\">setup</span><span class=\"p\">()</span>\n\n<span class=\"c1\"># Now this script or any imported module can use any part of Django it needs.</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">myapp</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">models</span>\n</code></pre></div>\n<p>Note that calling <code class=\"docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code> is only necessary if your code is truly\nstandalone. When invoked by your Web server, or through <a class=\"reference internal\" href=\"/ko/2.0/ref/django-admin/\"><span class=\"doc\">django-admin</span></a>, Django will handle this for you.</p>\n<aside class=\"admonition-django-setup-may-only-be-called-once admonition\">\n<p class=\"admonition-title\"><code class=\"docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code> may only be called once.</p>\n<p>Therefore, avoid putting reusable application logic in standalone scripts\nso that you have to import from the script elsewhere in your application.\nIf you can’t avoid that, put the call to <code class=\"docutils literal notranslate\"><span class=\"pre\">django.setup()</span></code> inside an\n<code class=\"docutils literal notranslate\"><span class=\"pre\">if</span></code> block:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">if</span> <span class=\"vm\">__name__</span> <span class=\"o\">==</span> <span class=\"s1\">&#39;__main__&#39;</span><span class=\"p\">:</span>\n    <span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">django</span>\n    <span class=\"n\">django</span><span class=\"o\">.</span><span class=\"n\">setup</span><span class=\"p\">()</span>\n</code></pre></div>\n</aside>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">더 보기</p>\n<dl class=\"simple\">\n<dt><a class=\"reference internal\" href=\"/ko/2.0/ref/settings/\"><span class=\"doc\">The Settings Reference</span></a></dt><dd><p>Contains the complete list of core and contrib app settings.</p>\n</dd>\n</dl>\n</aside>\n</section>\n</section>","rootId":"django-settings","toc":[{"title":"The basics","anchor":"the-basics","children":[]},{"title":"Designating the settings","anchor":"designating-the-settings","children":[{"title":"The django-admin utility","anchor":"the-django-admin-utility","children":[]},{"title":"On the server (mod_wsgi)","anchor":"on-the-server-mod-wsgi","children":[]}]},{"title":"Default settings","anchor":"default-settings","children":[{"title":"Seeing which settings you’ve changed","anchor":"seeing-which-settings-you-ve-changed","children":[]}]},{"title":"Using settings in Python code","anchor":"using-settings-in-python-code","children":[]},{"title":"Altering settings at runtime","anchor":"altering-settings-at-runtime","children":[]},{"title":"Security","anchor":"security","children":[]},{"title":"Available settings","anchor":"available-settings","children":[]},{"title":"Creating your own settings","anchor":"creating-your-own-settings","children":[]},{"title":"Using settings without setting DJANGO_SETTINGS_MODULE","anchor":"using-settings-without-setting-django-settings-module","children":[{"title":"Custom default settings","anchor":"custom-default-settings","children":[]},{"title":"Either configure() or DJANGO_SETTINGS_MODULE is required","anchor":"either-configure-or-django-settings-module-is-required","children":[]},{"title":"Calling django.setup() is required for “standalone” Django usage","anchor":"calling-django-setup-is-required-for-standalone-django-usage","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Using Django","url":"/ko/2.0/topics/"}],"prev":{"docname":"topics/serialization","title":"Serializing Django objects","url":"/ko/2.0/topics/serialization/"},"next":{"docname":"topics/signals","title":"Signals","url":"/ko/2.0/topics/signals/"},"formats":{"html":"/ko/2.0/topics/settings/","markdown":"/ko/2.0/topics/settings.md","json":"/ko/2.0/topics/settings.json"},"source":"https://github.com/django/django/blob/stable/2.0.x/docs/topics/settings.txt","official":"https://docs.djangoproject.com/ko/2.0/topics/settings/","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"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}