{"title":"Overriding templates","version":"1.11","locale":"ko","docname":"howto/overriding-templates","url":"/ko/1.11/howto/overriding-templates/","canonical":"https://djangodocs.dev/ko/1.11/howto/overriding-templates/","summary":"In your project, you might want to override a template in another Django application, whether it be a third-party application or a contrib application such as…","html":"<h1>Overriding templates<a class=\"heading-anchor\" href=\"#overriding-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>In your project, you might want to override a template in another Django\napplication, whether it be a third-party application or a contrib application\nsuch as <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.admin</span></code>. You can either put template overrides in your\nproject’s templates directory or in an application’s templates directory.</p>\n<p>If you have app and project templates directories that both contain overrides,\nthe default Django template loader will try to load the template from the\nproject-level directory first. In other words, <a class=\"reference internal\" href=\"/ko/1.11/ref/settings/#std-setting-TEMPLATES-DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DIRS</span></code></a>\nis searched before <a class=\"reference internal\" href=\"/ko/1.11/ref/settings/#std-setting-TEMPLATES-APP_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APP_DIRS</span></code></a>.</p>\n<section id=\"overriding-from-the-project-s-templates-directory\">\n<h2>Overriding from the project’s templates directory<a class=\"heading-anchor\" href=\"#overriding-from-the-project-s-templates-directory\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>First, we’ll explore overriding templates by creating replacement templates in\nyour project’s templates directory.</p>\n<p>Let’s say you’re trying to override the templates for a third-party application\ncalled <code class=\"docutils literal notranslate\"><span class=\"pre\">blog</span></code>, which provides the templates <code class=\"docutils literal notranslate\"><span class=\"pre\">blog/post.html</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">blog/list.html</span></code>. The relevant settings for your project would look like:</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\">BASE_DIR</span> <span class=\"o\">=</span> <span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">path</span><span class=\"o\">.</span><span class=\"n\">dirname</span><span class=\"p\">(</span><span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">path</span><span class=\"o\">.</span><span class=\"n\">dirname</span><span class=\"p\">(</span><span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">path</span><span class=\"o\">.</span><span class=\"n\">abspath</span><span class=\"p\">(</span><span class=\"vm\">__file__</span><span class=\"p\">)))</span>\n\n<span class=\"n\">INSTALLED_APPS</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;blog&#39;</span><span class=\"p\">,</span>\n    <span class=\"o\">...</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n\n<span class=\"n\">TEMPLATES</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">{</span>\n        <span class=\"s1\">&#39;BACKEND&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;django.template.backends.django.DjangoTemplates&#39;</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;DIRS&#39;</span><span class=\"p\">:</span> <span class=\"p\">[</span><span class=\"n\">os</span><span class=\"o\">.</span><span class=\"n\">path</span><span class=\"o\">.</span><span class=\"n\">join</span><span class=\"p\">(</span><span class=\"n\">BASE_DIR</span><span class=\"p\">,</span> <span class=\"s1\">&#39;templates&#39;</span><span class=\"p\">)],</span>\n        <span class=\"s1\">&#39;APP_DIRS&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"o\">...</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>The <a class=\"reference internal\" href=\"/ko/1.11/ref/settings/#std-setting-TEMPLATES\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">TEMPLATES</span></code></a> setting and <code class=\"docutils literal notranslate\"><span class=\"pre\">BASE_DIR</span></code> will already exist if you\ncreated your project using the default project template. The setting that needs\nto be modified is <a class=\"reference internal\" href=\"/ko/1.11/ref/settings/#std-setting-TEMPLATES-DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">DIRS</span></code></a>.</p>\n<p>These settings assume you have a <code class=\"docutils literal notranslate\"><span class=\"pre\">templates</span></code> directory in the root of your\nproject. To override the templates for the <code class=\"docutils literal notranslate\"><span class=\"pre\">blog</span></code> app, create a folder\nin the <code class=\"docutils literal notranslate\"><span class=\"pre\">templates</span></code> directory, and add the template files to that folder:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>templates/\n    blog/\n        list.html\n        post.html\n</code></pre></div>\n<p>The template loader first looks for templates in the <code class=\"docutils literal notranslate\"><span class=\"pre\">DIRS</span></code> directory. When\nthe views in the <code class=\"docutils literal notranslate\"><span class=\"pre\">blog</span></code> app ask for the <code class=\"docutils literal notranslate\"><span class=\"pre\">blog/post.html</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">blog/list.html</span></code> templates, the loader will return the files you just created.</p>\n</section>\n<section id=\"overriding-from-an-app-s-template-directory\">\n<h2>Overriding from an app’s template directory<a class=\"heading-anchor\" href=\"#overriding-from-an-app-s-template-directory\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Since you’re overriding templates located outside of one of your project’s\napps, it’s more common to use the first method and put template overrides in a\nproject’s templates folder. If you prefer, however, it’s also possible to put\nthe overrides in an app’s template directory.</p>\n<p>First, make sure your template settings are checking inside app directories:</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\">TEMPLATES</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"p\">{</span>\n        <span class=\"o\">...</span><span class=\"p\">,</span>\n        <span class=\"s1\">&#39;APP_DIRS&#39;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"o\">...</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>If you want to put the template overrides in an app called <code class=\"docutils literal notranslate\"><span class=\"pre\">myapp</span></code> and the\ntemplates to override are named <code class=\"docutils literal notranslate\"><span class=\"pre\">blog/list.html</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">blog/post.html</span></code>,\nthen your directory structure will look like:</p>\n<div class=\"code-block\" data-language=\"none\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">None</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=\"None code\"><code>myapp/\n    templates/\n        blog/\n            list.html\n            post.html\n</code></pre></div>\n<p>With <a class=\"reference internal\" href=\"/ko/1.11/ref/settings/#std-setting-TEMPLATES-APP_DIRS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APP_DIRS</span></code></a> set to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, the template\nloader will look in the app’s templates directory and find the templates.</p>\n</section>","rootId":"overriding-templates","toc":[{"title":"Overriding from the project’s templates directory","anchor":"overriding-from-the-project-s-templates-directory","children":[]},{"title":"Overriding from an app’s template directory","anchor":"overriding-from-an-app-s-template-directory","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"“How-to” guides","url":"/ko/1.11/howto/"}],"prev":{"docname":"howto/outputting-pdf","title":"Outputting PDFs with Django","url":"/ko/1.11/howto/outputting-pdf/"},"next":{"docname":"howto/static-files/index","title":"Managing static files (e.g. images, JavaScript, CSS)","url":"/ko/1.11/howto/static-files/"},"formats":{"html":"/ko/1.11/howto/overriding-templates/","markdown":"/ko/1.11/howto/overriding-templates.md","json":"/ko/1.11/howto/overriding-templates.json"},"source":"https://github.com/django/django/blob/stable/1.11.x/docs/howto/overriding-templates.txt","official":"https://docs.djangoproject.com/ko/1.11/howto/overriding-templates/","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","fr","ja","id","pt-br","ko","es","el","pl"]}