---
title: "django.urls functions for use in URLconfs"
version: 4.0
locale: pt-br
source: https://docs.djangoproject.com/pt-br/4.0/ref/urls/
canonical: https://djangodocs.dev/pt-br/4.0/ref/urls/
---
# `django.urls` functions for use in URLconfs

## `path()`

#### `path(route, view, kwargs=None, name=None)`

Returns an element for inclusion in `urlpatterns`. For example:

```
from django.urls import include, path

urlpatterns = [
    path('index/', views.index, name='main-view'),
    path('bio/<username>/', views.bio, name='bio'),
    path('articles/<slug:title>/', views.article, name='article-detail'),
    path('articles/<slug:title>/<int:section>/', views.section, name='article-section'),
    path('blog/', include('blog.urls')),
    ...
]
```

O argumento `route` deve ser uma string ou [`gettext_lazy()`](/pt-br/4.0/ref/utils/#django.utils.translation.gettext_lazy) (veja [Translating URL patterns](/pt-br/4.0/topics/i18n/translation/#translating-urlpatterns)) que contém um padrão de URL. A string pode conter colchetes angulares (como `<username>` acima) para capturar parte da URL e enviá-la como um argumento nomeado para a view. Os colchetes angulares podem incluir uma especificação do conversor (como a parte `int` de `2`) que limita os caracteres correspondidos e também podem alterar o tipo da variável passada para a view. Por exemplo, `<int:section>` corresponde a uma string de dígitos decimais e converte o valor em um `int`. Veja how-django-process-a-request para mais detalhes.

O argumento `view` é uma função de view ou o resultado de [`as_view()`](/pt-br/4.0/ref/class-based-views/base/#django.views.generic.base.View.as_view) para views baseadas em classe. Também pode ser um [`django.urls.include()`](#django.urls.include).

O argumento `kwargs` permite que você passe argumentos adicionais ao método ou função view. Veja [Passando opções extras para função “view”](/pt-br/4.0/topics/http/urls/#views-extra-options) para um exemplo.

Veja [Padrões de nomenclatura de URL](/pt-br/4.0/topics/http/urls/#naming-url-patterns) para o motivo do argumento `name` ser útil.

## `re_path()`

#### `re_path(route, view, kwargs=None, name=None)`

Returns an element for inclusion in `urlpatterns`. For example:

```
from django.urls import include, re_path

urlpatterns = [
    re_path(r'^index/$', views.index, name='index'),
    re_path(r'^bio/(?P<username>\w+)/$', views.bio, name='bio'),
    re_path(r'^blog/', include('blog.urls')),
    ...
]
```

The `route` argument should be a string or
[`gettext_lazy()`](/pt-br/4.0/ref/utils/#django.utils.translation.gettext_lazy) (see
[Translating URL patterns](/pt-br/4.0/topics/i18n/translation/#translating-urlpatterns)) that contains a regular expression compatible
with Python’s [`re`](https://docs.python.org/3/library/re.html#module-re) module. Strings typically use raw string syntax
(`r''`) so that they can contain sequences like `\d` without the need to
escape the backslash with another backslash. When a match is made, captured
groups from the regular expression are passed to the view – as named arguments
if the groups are named, and as positional arguments otherwise. The values are
passed as strings, without any type conversion.

When a `route` ends with `$` the whole requested URL, matching against
[`path_info`](/pt-br/4.0/ref/request-response/#django.http.HttpRequest.path_info), must match the regular expression
pattern ([`re.fullmatch()`](https://docs.python.org/3/library/re.html#re.fullmatch) is used).

The `view`, `kwargs` and `name` arguments are the same as for
[`path()`](#django.urls.path).

> **Changed in Django 2.2.25**
>
> In older versions, a full-match wasn’t required for a `route` which ends
> with `$`.

## `include()`

#### `include(module, namespace=None)`

#### `include(pattern_list)`

#### `include((pattern_list, app_namespace), namespace=None)`

A function that takes a full Python import path to another URLconf module
that should be “included” in this place. Optionally, the [application
namespace](/pt-br/4.0/topics/http/urls/#term-application-namespace) and [instance namespace](/pt-br/4.0/topics/http/urls/#term-instance-namespace) where the entries will be included
into can also be specified.

Usually, the application namespace should be specified by the included
module. If an application namespace is set, the `namespace` argument
can be used to set a different instance namespace.

`include()` also accepts as an argument either an iterable that returns
URL patterns or a 2-tuple containing such iterable plus the names of the
application namespaces.

**Parâmetros:** - `module` – URLconf module (or module name)
- `namespace` ([`str`](https://docs.python.org/3/library/stdtypes.html#str)) – Instance namespace for the URL entries being included
- `pattern_list` – Iterable of [`path()`](#django.urls.path) and/or [`re_path()`](#django.urls.re_path) instances.
- `app_namespace` ([`str`](https://docs.python.org/3/library/stdtypes.html#str)) – Application namespace for the URL entries being included

See [Incluindo outros URLconfs](/pt-br/4.0/topics/http/urls/#including-other-urlconfs) and [Domínios de nomes de URL e URLconfs incluídos](/pt-br/4.0/topics/http/urls/#namespaces-and-include).

## `register_converter()`

#### `register_converter(converter, type_name)`

The function for registering a converter for use in [`path()`](#django.urls.path)
`route`s.

The `converter` argument is a converter class, and `type_name` is the
converter name to use in path patterns. See
[Registering custom path converters](/pt-br/4.0/topics/http/urls/#registering-custom-path-converters) for an example.

# `django.conf.urls` functions for use in URLconfs

## `static()`

#### `static.static(prefix, view=django.views.static.serve, **kwargs)`

Helper function to return a URL pattern for serving files in debug mode:

```
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```

## `handler400`

#### `handler400`

A callable, or a string representing the full Python import path to the view
that should be called if the HTTP client has sent a request that caused an error
condition and a response with a status code of 400.

By default, this is [`django.views.defaults.bad_request()`](/pt-br/4.0/ref/views/#django.views.defaults.bad_request). If you
implement a custom view, be sure it accepts `request` and `exception`
arguments and returns an [`HttpResponseBadRequest`](/pt-br/4.0/ref/request-response/#django.http.HttpResponseBadRequest).

## `handler403`

#### `handler403`

A callable, or a string representing the full Python import path to the view
that should be called if the user doesn’t have the permissions required to
access a resource.

By default, this is [`django.views.defaults.permission_denied()`](/pt-br/4.0/ref/views/#django.views.defaults.permission_denied). If you
implement a custom view, be sure it accepts `request` and `exception`
arguments and returns an [`HttpResponseForbidden`](/pt-br/4.0/ref/request-response/#django.http.HttpResponseForbidden).

## `handler404`

#### `handler404`

A callable, or a string representing the full Python import path to the view
that should be called if none of the URL patterns match.

By default, this is [`django.views.defaults.page_not_found()`](/pt-br/4.0/ref/views/#django.views.defaults.page_not_found). If you
implement a custom view, be sure it accepts `request` and `exception`
arguments and returns an [`HttpResponseNotFound`](/pt-br/4.0/ref/request-response/#django.http.HttpResponseNotFound).

## `handler500`

#### `handler500`

A callable, or a string representing the full Python import path to the view
that should be called in case of server errors. Server errors happen when you
have runtime errors in view code.

By default, this is [`django.views.defaults.server_error()`](/pt-br/4.0/ref/views/#django.views.defaults.server_error). If you
implement a custom view, be sure it accepts a `request` argument and returns
an [`HttpResponseServerError`](/pt-br/4.0/ref/request-response/#django.http.HttpResponseServerError).
