django.conf.urls utility functionsLink to this heading
static()Link to this heading
- static.static(prefix, view=django.views.static.serve, **kwargs)Link to this definition
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)
url()Link to this heading
- url(regex, view, kwargs=None, name=None)Link to this definition
urlpatterns should be a list of url() instances. For example:
from django.conf.urls import include, url
urlpatterns = [
url(r'^index/$', index_view, name='main-view'),
url(r'^weblog/', include('blog.urls')),
...
]
The regex parameter should be a string or
ugettext_lazy() (see
Translating URL patterns) that contains a regular expression compatible
with Python’s 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.
The view parameter is a view function or the result of
as_view() for class-based views. It can
also be an include().
The kwargs parameter allows you to pass additional arguments to the view
function or method. See Passing extra options to view functions for an example.
See Naming URL patterns for why the name
parameter is useful.
include()Link to this heading
- include(module, namespace=None, app_name=None)Link to this definition
- include(pattern_list)
- include((pattern_list, app_namespace), namespace=None)
- include((pattern_list, app_namespace, instance_namespace))
A function that takes a full Python import path to another URLconf module that should be «included» in this place. Optionally, the application namespace and 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
namespaceargument can be used to set a different instance namespace.include()also accepts as an argument either an iterable that returns URL patterns, a 2-tuple containing such iterable plus the names of the application namespaces, or a 3-tuple containing the iterable and the names of both the application and instance namespace.- Παράμετροι:
module – URLconf module (or module name)
namespace (str) – Instance namespace for the URL entries being included
app_name (str) – Application namespace for the URL entries being included
pattern_list – Iterable of
django.conf.urls.url()instancesapp_namespace (str) – Application namespace for the URL entries being included
instance_namespace (str) – Instance namespace for the URL entries being included
See Including other URLconfs and URL namespaces and included URLconfs.
handler400Link to this heading
- handler400Link to this definition
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'. If you
implement a custom view, be sure it returns an
HttpResponseBadRequest.
See the documentation about the 400 (bad request) view for more information.
handler403Link to this heading
- handler403Link to this definition
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'. If you
implement a custom view, be sure it returns an
HttpResponseForbidden.
See the documentation about the 403 (HTTP Forbidden) view for more information.
handler404Link to this heading
- handler404Link to this definition
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'. If you
implement a custom view, be sure it returns an
HttpResponseNotFound.
See the documentation about the 404 (HTTP Not Found) view for more information.
handler500Link to this heading
- handler500Link to this definition
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'. If you
implement a custom view, be sure it returns an
HttpResponseServerError.
See the documentation about the 500 (HTTP Internal Server Error) view for more information.