{"title":"Format localization","version":"2.2","locale":"ko","docname":"topics/i18n/formatting","url":"/ko/2.2/topics/i18n/formatting/","canonical":"https://djangodocs.dev/ko/2.2/topics/i18n/formatting/","summary":"개요 Link to this heading # Django’s formatting system is capable of displaying dates, times and numbers in templates using the format specified for the current…","html":"<h1>Format localization<a class=\"heading-anchor\" href=\"#format-localization\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"overview\">\n<h2>개요<a class=\"heading-anchor\" href=\"#overview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django’s formatting system is capable of displaying dates, times and numbers in\ntemplates using the format specified for the current\n<a class=\"reference internal\" href=\"/ko/2.2/topics/i18n/#term-locale-name\"><span class=\"xref std std-term\">locale</span></a>. It also handles localized input in forms.</p>\n<p>When it’s enabled, two users accessing the same content may see dates, times and\nnumbers formatted in different ways, depending on the formats for their current\nlocale.</p>\n<p>The formatting system is disabled by default. To enable it, it’s\nnecessary to set <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span> <span class=\"pre\">=</span> <span class=\"pre\">True</span></code></a> in your settings file.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>The default <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> file created by <a class=\"reference internal\" href=\"/ko/2.2/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span>\n<span class=\"pre\">startproject</span></code></a> includes <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span> <span class=\"pre\">=</span> <span class=\"pre\">True</span></code></a>\nfor convenience.  Note, however, that to enable number formatting with\nthousand separators it is necessary to set <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_THOUSAND_SEPARATOR\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_THOUSAND_SEPARATOR</span>\n<span class=\"pre\">=</span> <span class=\"pre\">True</span></code></a> in your settings file. Alternatively, you\ncould use <a class=\"reference internal\" href=\"/ko/2.2/ref/contrib/humanize/#std-templatefilter-intcomma\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">intcomma</span></code></a> to format numbers in your template.</p>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>There is also an independent but related <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_I18N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_I18N</span></code></a> setting that\ncontrols if Django should activate translation. See\n<a class=\"reference internal\" href=\"/ko/2.2/topics/i18n/translation/\"><span class=\"doc\">번역</span></a> for more details.</p>\n</aside>\n</section>\n<section id=\"locale-aware-input-in-forms\">\n<h2>Locale aware input in forms<a class=\"heading-anchor\" href=\"#locale-aware-input-in-forms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When formatting is enabled, Django can use localized formats when parsing dates,\ntimes and numbers in forms. That means it tries different formats for different\nlocales when guessing the format used by the user when inputting data on forms.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>Django uses different formats for displaying data to those it uses for\nparsing data. Most notably, the formats for parsing dates can’t use the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">%a</span></code> (abbreviated weekday name), <code class=\"docutils literal notranslate\"><span class=\"pre\">%A</span></code> (full weekday name),\n<code class=\"docutils literal notranslate\"><span class=\"pre\">%b</span></code> (abbreviated month name), <code class=\"docutils literal notranslate\"><span class=\"pre\">%B</span></code> (full month name),\nor <code class=\"docutils literal notranslate\"><span class=\"pre\">%p</span></code> (AM/PM).</p>\n</aside>\n<p>To enable a form field to localize input and output data simply use its\n<code class=\"docutils literal notranslate\"><span class=\"pre\">localize</span></code> argument:</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\">class</span><span class=\"w\"> </span><span class=\"nc\">CashRegisterForm</span><span class=\"p\">(</span><span class=\"n\">forms</span><span class=\"o\">.</span><span class=\"n\">Form</span><span class=\"p\">):</span>\n   <span class=\"n\">product</span> <span class=\"o\">=</span> <span class=\"n\">forms</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">()</span>\n   <span class=\"n\">revenue</span> <span class=\"o\">=</span> <span class=\"n\">forms</span><span class=\"o\">.</span><span class=\"n\">DecimalField</span><span class=\"p\">(</span><span class=\"n\">max_digits</span><span class=\"o\">=</span><span class=\"mi\">4</span><span class=\"p\">,</span> <span class=\"n\">decimal_places</span><span class=\"o\">=</span><span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"n\">localize</span><span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"controlling-localization-in-templates\">\n<span id=\"topic-l10n-templates\"></span><h2>Controlling localization in templates<a class=\"heading-anchor\" href=\"#controlling-localization-in-templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When you have enabled formatting with <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span></code></a>, Django\nwill try to use a locale specific format whenever it outputs a value\nin a template.</p>\n<p>However, it may not always be appropriate to use localized values –\nfor example, if you’re outputting JavaScript or XML that is designed\nto be machine-readable, you will always want unlocalized values. You\nmay also want to use localization in selected templates, rather than\nusing localization everywhere.</p>\n<p>To allow for fine control over the use of localization, Django\nprovides the <code class=\"docutils literal notranslate\"><span class=\"pre\">l10n</span></code> template library that contains the following\ntags and filters.</p>\n<section id=\"template-tags\">\n<h3>템플릿 태그<a class=\"heading-anchor\" href=\"#template-tags\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"localize\">\n<span id=\"std-templatetag-localize\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">localize</span></code><a class=\"heading-anchor\" href=\"#localize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Enables or disables localization of template variables in the\ncontained block.</p>\n<p>This tag allows a more fine grained control of localization than\n<a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span></code></a>.</p>\n<p>To activate or deactivate localization for a template block, use:</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=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">load</span> <span class=\"n\">l10n</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n\n<span class=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">localize</span> <span class=\"n\">on</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n    <span class=\"p\">{{</span> <span class=\"n\">value</span> <span class=\"p\">}}</span>\n<span class=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">endlocalize</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n\n<span class=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">localize</span> <span class=\"n\">off</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n    <span class=\"p\">{{</span> <span class=\"n\">value</span> <span class=\"p\">}}</span>\n<span class=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">endlocalize</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">참고</p>\n<p>The value of <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-USE_L10N\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">USE_L10N</span></code></a> isn’t respected inside of a\n<code class=\"docutils literal notranslate\"><span class=\"pre\">{%</span> <span class=\"pre\">localize</span> <span class=\"pre\">%}</span></code> block.</p>\n</aside>\n<p>See <a class=\"reference internal\" href=\"#std-templatefilter-localize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">localize</span></code></a> and <a class=\"reference internal\" href=\"#std-templatefilter-unlocalize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">unlocalize</span></code></a> for template filters that will\ndo the same job on a per-variable basis.</p>\n</section>\n</section>\n<section id=\"template-filters\">\n<h3>템플릿 필터<a class=\"heading-anchor\" href=\"#template-filters\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"std-templatefilter-localize\">\n<span id=\"id1\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">localize</span></code><a class=\"heading-anchor\" href=\"#std-templatefilter-localize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Forces localization of a single value.</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=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">load</span> <span class=\"n\">l10n</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n\n<span class=\"p\">{{</span> <span class=\"n\">value</span><span class=\"o\">|</span><span class=\"n\">localize</span> <span class=\"p\">}}</span>\n</code></pre></div>\n<p>To disable localization on a single value, use <a class=\"reference internal\" href=\"#std-templatefilter-unlocalize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">unlocalize</span></code></a>. To control\nlocalization over a large section of a template, use the <a class=\"reference internal\" href=\"#std-templatetag-localize\"><code class=\"xref std std-ttag docutils literal notranslate\"><span class=\"pre\">localize</span></code></a> template\ntag.</p>\n</section>\n<section id=\"unlocalize\">\n<span id=\"std-templatefilter-unlocalize\"></span><h4><code class=\"docutils literal notranslate\"><span class=\"pre\">unlocalize</span></code><a class=\"heading-anchor\" href=\"#unlocalize\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Forces a single value to be printed without localization.</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=\"p\">{</span><span class=\"o\">%</span> <span class=\"n\">load</span> <span class=\"n\">l10n</span> <span class=\"o\">%</span><span class=\"p\">}</span>\n\n<span class=\"p\">{{</span> <span class=\"n\">value</span><span class=\"o\">|</span><span class=\"n\">unlocalize</span> <span class=\"p\">}}</span>\n</code></pre></div>\n<p>To force localization of a single value, use <a class=\"reference internal\" href=\"#std-templatefilter-localize\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">localize</span></code></a>. To\ncontrol localization over a large section of a template, use the\n<a class=\"reference internal\" href=\"#std-templatetag-localize\"><code class=\"xref std std-ttag docutils literal notranslate\"><span class=\"pre\">localize</span></code></a> template tag.</p>\n</section>\n</section>\n</section>\n<section id=\"creating-custom-format-files\">\n<span id=\"custom-format-files\"></span><h2>Creating custom format files<a class=\"heading-anchor\" href=\"#creating-custom-format-files\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django provides format definitions for many locales, but sometimes you might\nwant to create your own, because a format files doesn’t exist for your locale,\nor because you want to overwrite some of the values.</p>\n<p>To use custom formats, specify the path where you’ll place format files\nfirst. To do that, just set your <a class=\"reference internal\" href=\"/ko/2.2/ref/settings/#std-setting-FORMAT_MODULE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">FORMAT_MODULE_PATH</span></code></a> setting to\nthe package where format files will exist, for instance:</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\">FORMAT_MODULE_PATH</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"s1\">&#39;mysite.formats&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;some_app.formats&#39;</span><span class=\"p\">,</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Files are not placed directly in this directory, but in a directory named as\nthe locale, and must be named <code class=\"docutils literal notranslate\"><span class=\"pre\">formats.py</span></code>. Be careful not to put sensitive\ninformation in these files as values inside can be exposed if you pass the\nstring to <code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.formats.get_format()</span></code> (used by the <a class=\"reference internal\" href=\"/ko/2.2/ref/templates/builtins/#std-templatefilter-date\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">date</span></code></a>\ntemplate filter).</p>\n<p>To customize the English formats, a structure like this would be needed:</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\">mysite</span><span class=\"o\">/</span>\n    <span class=\"n\">formats</span><span class=\"o\">/</span>\n        <span class=\"fm\">__init__</span><span class=\"o\">.</span><span class=\"n\">py</span>\n        <span class=\"n\">en</span><span class=\"o\">/</span>\n            <span class=\"fm\">__init__</span><span class=\"o\">.</span><span class=\"n\">py</span>\n            <span class=\"n\">formats</span><span class=\"o\">.</span><span class=\"n\">py</span>\n</code></pre></div>\n<p>where <code class=\"file docutils literal notranslate\"><span class=\"pre\">formats.py</span></code> contains custom format definitions. 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=\"n\">THOUSAND_SEPARATOR</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;</span><span class=\"se\">\\xa0</span><span class=\"s1\">&#39;</span>\n</code></pre></div>\n<p>to use a non-breaking space (Unicode <code class=\"docutils literal notranslate\"><span class=\"pre\">00A0</span></code>) as a thousand separator,\ninstead of the default for English, a comma.</p>\n</section>\n<section id=\"limitations-of-the-provided-locale-formats\">\n<h2>Limitations of the provided locale formats<a class=\"heading-anchor\" href=\"#limitations-of-the-provided-locale-formats\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Some locales use context-sensitive formats for numbers, which Django’s\nlocalization system cannot handle automatically.</p>\n<section id=\"switzerland-german\">\n<h3>Switzerland (German)<a class=\"heading-anchor\" href=\"#switzerland-german\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The Swiss number formatting depends on the type of number that is being\nformatted. For monetary values, a comma is used as the thousand separator and\na decimal point for the decimal separator. For all other numbers, a comma is\nused as decimal separator and a space as thousand separator. The locale format\nprovided by Django uses the generic separators, a comma for decimal and a space\nfor thousand separators.</p>\n</section>\n</section>","rootId":"format-localization","toc":[{"title":"개요","anchor":"overview","children":[]},{"title":"Locale aware input in forms","anchor":"locale-aware-input-in-forms","children":[]},{"title":"Controlling localization in templates","anchor":"controlling-localization-in-templates","children":[{"title":"템플릿 태그","anchor":"template-tags","children":[{"title":"localize","anchor":"localize","children":[]}]},{"title":"템플릿 필터","anchor":"template-filters","children":[{"title":"localize","anchor":"std-templatefilter-localize","children":[]},{"title":"unlocalize","anchor":"unlocalize","children":[]}]}]},{"title":"Creating custom format files","anchor":"creating-custom-format-files","children":[]},{"title":"Limitations of the provided locale formats","anchor":"limitations-of-the-provided-locale-formats","children":[{"title":"Switzerland (German)","anchor":"switzerland-german","children":[]}]}],"breadcrumbs":[{"docname":"topics/index","title":"Django 사용하기","url":"/ko/2.2/topics/"},{"docname":"topics/i18n/index","title":"국제화와 현지화","url":"/ko/2.2/topics/i18n/"}],"prev":{"docname":"topics/i18n/translation","title":"번역","url":"/ko/2.2/topics/i18n/translation/"},"next":{"docname":"topics/i18n/timezones","title":"Time zones","url":"/ko/2.2/topics/i18n/timezones/"},"formats":{"html":"/ko/2.2/topics/i18n/formatting/","markdown":"/ko/2.2/topics/i18n/formatting.md","json":"/ko/2.2/topics/i18n/formatting.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/topics/i18n/formatting.txt","official":"https://docs.djangoproject.com/ko/2.2/topics/i18n/formatting/","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"]}