django.urls functions for use in URLconfs

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

The view argument is a view function or the result of for class-based views. It canalso be an django.urls.include().

The kwargs argument allows you to pass additional arguments to the viewfunction or method. See for an example.

See Naming URL patterns for why the nameargument is useful.

re_path()

  • repath(_route, view, kwargs=None, name=None)
  • Returns an element for inclusion in urlpatterns. For example:

The route argument should be a string or (seeTranslating URL patterns) that contains a regular expression compatiblewith Python's module. Strings typically use raw string syntax() so that they can contain sequences like \d without the need toescape the backslash with another backslash. When a match is made, capturedgroups from the regular expression are passed to the view — as named argumentsif the groups are named, and as positional arguments otherwise. The values arepassed as strings, without any type conversion.

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 modulethat should be "included" in this place. Optionally, the and instance namespace where the entries will be includedinto can also be specified.

Usually, the application namespace should be specified by the includedmodule. If an application namespace is set, the namespace argumentcan be used to set a different instance namespace.

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

参数:

  • module — URLconf module (or module name)
  • namespace () — Instance namespace for the URL entries being included
  • pattern_list — Iterable of path() and/or instances.
  • app_namespace (str) — Application namespace for the URL entries being included

See and URL namespaces and included URLconfs.

  • The function for registering a converter for use in routes.

django.conf.urls functions for use in URLconfs

static()

  • static.(prefix, view=django.views.static.serve, **kwargs)
  • Helper function to return a URL pattern for serving files in debug mode:

url()

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

By default, this is django.views.defaults.bad_request(). If youimplement a custom view, be sure it accepts request and exceptionarguments and returns an .

handler403

  • handler403
  • A callable, or a string representing the full Python import path to the viewthat should be called if the user doesn't have the permissions required toaccess a resource.

By default, this is django.views.defaults.permission_denied(). If youimplement a custom view, be sure it accepts request and exceptionarguments and returns an .

handler404

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

By default, this is django.views.defaults.page_not_found(). If youimplement a custom view, be sure it accepts request and exceptionarguments and returns an .

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

By default, this is . If youimplement a custom view, be sure it returns an.