django.conf.urls utility functions¶
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)
url(regex, view, kwargs=None, name=None)¶
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')), ... ]
regex parameter should be a string or
Translating URL patterns) that contains a regular expression compatible
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.
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
parameter is useful.
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 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 or a 2-tuple containing such iterable plus the names of the application namespaces.
- module – URLconf module (or module name)
- namespace (string) – Instance namespace for the URL entries being included
- pattern_list – Iterable of
- app_namespace (string) – Application namespace for the URL entries being included
- instance_namespace (string) – Instance namespace for the URL entries being included
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.
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.
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.
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.