{"title":"Fungsi-fungsi kegunaan django.conf.urls","version":"1.11","locale":"id","docname":"ref/urls","url":"/id/1.11/ref/urls/","canonical":"https://djangodocs.dev/id/1.11/ref/urls/","summary":"static() Link to this heading # static. static ( prefix , view = django.views.static.serve , ** kwargs ) Link to this definition # Helper function to return a URL…","html":"<span id=\"django-conf-urls-utility-functions\"></span><h1>Fungsi-fungsi kegunaan <code class=\"docutils literal notranslate\"><span class=\"pre\">django.conf.urls</span></code><a class=\"heading-anchor\" href=\"#module-django.conf.urls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"static\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">static()</span></code><a class=\"heading-anchor\" href=\"#static\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.conf.urls.static.static\">\n<span class=\"sig-prename descclassname\"><span class=\"pre\">static.</span></span><span class=\"sig-name descname\"><span class=\"pre\">static</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">prefix</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">view</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">django.views.static.serve</span></span></em>, <em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">kwargs</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.conf.urls.static.static\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>Helper function to return a URL pattern for serving files in debug mode:</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\">django.conf.urls.static</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">static</span>\n\n<span class=\"n\">urlpatterns</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"c1\"># ... the rest of your URLconf goes here ...</span>\n<span class=\"p\">]</span> <span class=\"o\">+</span> <span class=\"n\">static</span><span class=\"p\">(</span><span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">MEDIA_URL</span><span class=\"p\">,</span> <span class=\"n\">document_root</span><span class=\"o\">=</span><span class=\"n\">settings</span><span class=\"o\">.</span><span class=\"n\">MEDIA_ROOT</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"url\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">url()</span></code><a class=\"heading-anchor\" href=\"#url\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.conf.urls.url\">\n<span class=\"sig-name descname\"><span class=\"pre\">url</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">regex</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">view</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">kwargs</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">name</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.conf.urls.url\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">urlpatterns</span></code> should be a list of <code class=\"docutils literal notranslate\"><span class=\"pre\">url()</span></code> instances. 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.urls</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">include</span><span class=\"p\">,</span> <span class=\"n\">url</span>\n\n<span class=\"n\">urlpatterns</span> <span class=\"o\">=</span> <span class=\"p\">[</span>\n    <span class=\"n\">url</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^index/$&#39;</span><span class=\"p\">,</span> <span class=\"n\">index_view</span><span class=\"p\">,</span> <span class=\"n\">name</span><span class=\"o\">=</span><span class=\"s1\">&#39;main-view&#39;</span><span class=\"p\">),</span>\n    <span class=\"n\">url</span><span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^weblog/&#39;</span><span class=\"p\">,</span> <span class=\"n\">include</span><span class=\"p\">(</span><span class=\"s1\">&#39;blog.urls&#39;</span><span class=\"p\">)),</span>\n    <span class=\"o\">...</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p>Parameter <code class=\"docutils literal notranslate\"><span class=\"pre\">regex</span></code> harus berupa string atau <a class=\"reference internal\" href=\"/id/1.11/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> (lihat <a class=\"reference internal\" href=\"/id/1.11/topics/i18n/translation/#translating-urlpatterns\"><span class=\"std std-ref\">Menterjemahkan pola URL</span></a>) yang mengandung kecocokan regular expression dengan modul <a class=\"reference external\" href=\"https://docs.python.org/3/library/re.html#module-re\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">re</span></code></a> Python. String khususnya menggunakan sintaksis string mentah (<code class=\"docutils literal notranslate\"><span class=\"pre\">r''</span></code>) sehingga mereka dapat mengandung urutan seperti <code class=\"docutils literal notranslate\"><span class=\"pre\">\\d</span></code> tanpa butuh meloloskan garis miring dengan garis miring lain.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">view</span></code> parameter is a view function or the result of\n<a class=\"reference internal\" href=\"/id/1.11/ref/class-based-views/base/#django.views.generic.base.View.as_view\" title=\"django.views.generic.base.View.as_view\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">as_view()</span></code></a> for class-based views. It can\nalso be an <a class=\"reference internal\" href=\"#django.conf.urls.include\" title=\"django.conf.urls.include\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">include()</span></code></a>.</p>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">kwargs</span></code> parameter allows you to pass additional arguments to the view\nfunction or method. See <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#views-extra-options\"><span class=\"std std-ref\">Melewatkan pilihan tambahan untuk melihat fungsi</span></a> for an example.</p>\n<p>See <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#naming-url-patterns\"><span class=\"std std-ref\">Naming URL patterns</span></a> for why the <code class=\"docutils literal notranslate\"><span class=\"pre\">name</span></code>\nparameter is useful.</p>\n</section>\n<section id=\"include\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">include()</span></code><a class=\"heading-anchor\" href=\"#include\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.conf.urls.include\">\n<span class=\"sig-name descname\"><span class=\"pre\">include</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">module</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">namespace</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_name</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.conf.urls.include\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dt class=\"sig sig-object py\">\n<span class=\"sig-name descname\"><span class=\"pre\">include</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">pattern_list</span></span></em><span class=\"sig-paren\">)</span></dt>\n<dt class=\"sig sig-object py\">\n<span class=\"sig-name descname\"><span class=\"pre\">include</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">(pattern_list</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_namespace)</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">namespace=None</span></span></em><span class=\"sig-paren\">)</span></dt>\n<dt class=\"sig sig-object py\">\n<span class=\"sig-name descname\"><span class=\"pre\">include</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">(pattern_list</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">app_namespace</span></span></em>, <em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">instance_namespace)</span></span></em><span class=\"sig-paren\">)</span></dt>\n<dd><p>A function that takes a full Python import path to another URLconf module\nthat should be &quot;included&quot; in this place. Optionally, the <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#term-application-namespace\"><span class=\"xref std std-term\">application\nnamespace</span></a> and <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#term-instance-namespace\"><span class=\"xref std std-term\">instance namespace</span></a> where the entries will be included\ninto can also be specified.</p>\n<p>Usually, the application namespace should be specified by the included\nmodule. If an application namespace is set, the <code class=\"docutils literal notranslate\"><span class=\"pre\">namespace</span></code> argument\ncan be used to set a different instance namespace.</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">include()</span></code> also accepts as an argument either an iterable that returns\nURL patterns, a 2-tuple containing such iterable plus the names of the\napplication namespaces, or a 3-tuple containing the iterable and the names\nof both the application and instance namespace.</p>\n<dl class=\"field-list simple\">\n<dt class=\"field-odd\">Parameter<span class=\"colon\">:</span></dt>\n<dd class=\"field-odd\"><ul class=\"simple\">\n<li><p><strong>module</strong> -- URLconf module (or module name)</p></li>\n<li><p><strong>namespace</strong> (<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str\" title=\"(di Python v3.14)\"><em>str</em></a>) -- Instance namespace for the URL entries being included</p></li>\n<li><p><strong>app_name</strong> (<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str\" title=\"(di Python v3.14)\"><em>str</em></a>) -- Application namespace for the URL entries being included</p></li>\n<li><p><strong>pattern_list</strong> -- Iterable of <a class=\"reference internal\" href=\"#django.conf.urls.url\" title=\"django.conf.urls.url\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.conf.urls.url()</span></code></a> instances</p></li>\n<li><p><strong>app_namespace</strong> (<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str\" title=\"(di Python v3.14)\"><em>str</em></a>) -- Application namespace for the URL entries being included</p></li>\n<li><p><strong>instance_namespace</strong> (<a class=\"reference external\" href=\"https://docs.python.org/3/library/stdtypes.html#str\" title=\"(di Python v3.14)\"><em>str</em></a>) -- Instance namespace for the URL entries being included</p></li>\n</ul>\n</dd>\n</dl>\n</dd></dl>\n\n<p>See <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#including-other-urlconfs\"><span class=\"std std-ref\">Menyertakan URLconf lain</span></a> and <a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#namespaces-and-include\"><span class=\"std std-ref\">Namespace URL dan URLconf disertakan</span></a>.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"1.9\">\n<p class=\"version-note-title\">Deprecated since Django 1.9</p><p><span class=\"versionmodified deprecated\">Ditinggalkan sejak versi 1.9: </span>Support for the <code class=\"docutils literal notranslate\"><span class=\"pre\">app_name</span></code> argument is deprecated and will be removed in\nDjango 2.0. Specify the <code class=\"docutils literal notranslate\"><span class=\"pre\">app_name</span></code> as explained in\n<a class=\"reference internal\" href=\"/id/1.11/topics/http/urls/#namespaces-and-include\"><span class=\"std std-ref\">Namespace URL dan URLconf disertakan</span></a> instead.</p>\n<p>Support for passing a 3-tuple is also deprecated and will be removed in\nDjango 2.0. Pass a 2-tuple containing the pattern list and application\nnamespace, and use the <code class=\"docutils literal notranslate\"><span class=\"pre\">namespace</span></code> argument instead.</p>\n<p>Lastly, support for an instance namespace without an application namespace\nhas been deprecated and will be removed in Django 2.0. Specify the\napplication namespace or remove the instance namespace.</p>\n</aside>\n</section>\n<section id=\"handler400\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">handler400</span></code><a class=\"heading-anchor\" href=\"#handler400\"><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.conf.urls.handler400\">\n<span class=\"sig-name descname\"><span class=\"pre\">handler400</span></span><a class=\"heading-anchor\" href=\"#django.conf.urls.handler400\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A callable, or a string representing the full Python import path to the view\nthat should be called if the HTTP client has sent a request that caused an error\ncondition and a response with a status code of 400.</p>\n<p>By default, this is <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.views.defaults.bad_request'</span></code>. If you\nimplement a custom view, be sure it returns an\n<a class=\"reference internal\" href=\"/id/1.11/ref/request-response/#django.http.HttpResponseBadRequest\" title=\"django.http.HttpResponseBadRequest\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseBadRequest</span></code></a>.</p>\n<p>See the documentation about <a class=\"reference internal\" href=\"/id/1.11/ref/views/#http-bad-request-view\"><span class=\"std std-ref\">the 400 (bad request) view</span></a> for more information.</p>\n</section>\n<section id=\"handler403\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">handler403</span></code><a class=\"heading-anchor\" href=\"#handler403\"><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.conf.urls.handler403\">\n<span class=\"sig-name descname\"><span class=\"pre\">handler403</span></span><a class=\"heading-anchor\" href=\"#django.conf.urls.handler403\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A callable, or a string representing the full Python import path to the view\nthat should be called if the user doesn't have the permissions required to\naccess a resource.</p>\n<p>By default, this is <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.views.defaults.permission_denied'</span></code>. If you\nimplement a custom view, be sure it returns an\n<a class=\"reference internal\" href=\"/id/1.11/ref/request-response/#django.http.HttpResponseForbidden\" title=\"django.http.HttpResponseForbidden\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseForbidden</span></code></a>.</p>\n<p>See the documentation about <a class=\"reference internal\" href=\"/id/1.11/ref/views/#http-forbidden-view\"><span class=\"std std-ref\">the 403 (HTTP Forbidden) view</span></a> for more information.</p>\n</section>\n<section id=\"handler404\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">handler404</span></code><a class=\"heading-anchor\" href=\"#handler404\"><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.conf.urls.handler404\">\n<span class=\"sig-name descname\"><span class=\"pre\">handler404</span></span><a class=\"heading-anchor\" href=\"#django.conf.urls.handler404\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A callable, or a string representing the full Python import path to the view\nthat should be called if none of the URL patterns match.</p>\n<p>By default, this is <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.views.defaults.page_not_found'</span></code>. If you\nimplement a custom view, be sure it returns an\n<a class=\"reference internal\" href=\"/id/1.11/ref/request-response/#django.http.HttpResponseNotFound\" title=\"django.http.HttpResponseNotFound\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseNotFound</span></code></a>.</p>\n<p>See the documentation about <a class=\"reference internal\" href=\"/id/1.11/ref/views/#http-not-found-view\"><span class=\"std std-ref\">the 404 (HTTP Not Found) view</span></a> for more information.</p>\n</section>\n<section id=\"handler500\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">handler500</span></code><a class=\"heading-anchor\" href=\"#handler500\"><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.conf.urls.handler500\">\n<span class=\"sig-name descname\"><span class=\"pre\">handler500</span></span><a class=\"heading-anchor\" href=\"#django.conf.urls.handler500\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p>A callable, or a string representing the full Python import path to the view\nthat should be called in case of server errors. Server errors happen when you\nhave runtime errors in view code.</p>\n<p>By default, this is <code class=\"docutils literal notranslate\"><span class=\"pre\">'django.views.defaults.server_error'</span></code>. If you\nimplement a custom view, be sure it returns an\n<a class=\"reference internal\" href=\"/id/1.11/ref/request-response/#django.http.HttpResponseServerError\" title=\"django.http.HttpResponseServerError\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponseServerError</span></code></a>.</p>\n<p>See the documentation about <a class=\"reference internal\" href=\"/id/1.11/ref/views/#http-internal-server-error-view\"><span class=\"std std-ref\">the 500 (HTTP Internal Server Error) view</span></a> for more information.</p>\n</section>","rootId":"module-django.conf.urls","toc":[{"title":"static()","anchor":"static","children":[]},{"title":"url()","anchor":"url","children":[]},{"title":"include()","anchor":"include","children":[]},{"title":"handler400","anchor":"handler400","children":[]},{"title":"handler403","anchor":"handler403","children":[]},{"title":"handler404","anchor":"handler404","children":[]},{"title":"handler500","anchor":"handler500","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"Acuan API","url":"/id/1.11/ref/"}],"prev":{"docname":"ref/urlresolvers","title":"Fungsi-fungsi kegunaan django.urls","url":"/id/1.11/ref/urlresolvers/"},"next":{"docname":"ref/utils","title":"Perlengkapan Django","url":"/id/1.11/ref/utils/"},"formats":{"html":"/id/1.11/ref/urls/","markdown":"/id/1.11/ref/urls.md","json":"/id/1.11/ref/urls.json"},"source":"https://github.com/django/django/blob/stable/1.11.x/docs/ref/urls.txt","official":"https://docs.djangoproject.com/id/1.11/ref/urls/","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","ko","es","el","pl"]}