urls.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from django.urls import include, path
  2. #
  3. # On Reversing URLs
  4. # =================
  5. #
  6. # Recommended Usage:
  7. # Always use rest_framework.reverse.reverse, do not directly use django.urls.reverse.
  8. # If a request object r is available, use reverse(name, request=r). With the name as defined
  9. # in desecapi.urls.v1 or desecapi.urls.v2. It will return an URL maintaining the currently requested API version.
  10. # If there is no request object available, e.g. in commands, a mock object can be constructed
  11. # carrying all information that is necessary to construct a full URL:
  12. #
  13. # from django.conf import settings
  14. # from django.test import RequestFactory
  15. # from rest_framework.versioning import NamespaceVersioning
  16. #
  17. # r = RequestFactory().request(HTTP_HOST=settings.ALLOWED_HOSTS[0])
  18. # r.version = 'v1'
  19. # r.versioning_scheme = NamespaceVersioning()
  20. #
  21. # Also note in this context settings.REST_FRAMEWORK['ALLOWED_VERSIONS'] and
  22. # settings.REST_FRAMEWORK['DEFAULT_VERSIONING_CLASS']. (The latter is of type string.)
  23. #
  24. # Advanced Usage:
  25. # Prefix the name of any path with 'desecapi' to get the default version,
  26. # or prefix the name of any path with the desired namespace, e.g. 'v1:root'.
  27. # In this case, the version information of the request will be ignored and
  28. # providing a request object is optional. However, if no request object is provided,
  29. # only a relative URL can be generated.
  30. #
  31. # Examples:
  32. # The examples refer to the version used by the client to connect as the REQUESTED version,
  33. # the version specified by the first argument to reverse as the SPECIFIED version, and to the
  34. # version defined as default (see below) as the DEFAULT version.
  35. #
  36. # reverse('root', request) -> absolute URL, e.g. https://.../api/v1/, with the REQUESTED version
  37. # reverse('root') -> django.urls.exceptions.NoReverseMatch
  38. # reverse('desecapi:root') -> relative URL, e.g. api/v1/, with the DEFAULT version
  39. # reverse('v2:root') -> relative URL, e.g. api/v2/, with the SPECIFIED version
  40. # reverse('v2:root', request) -> absolute URL, e.g. https://.../api/v2/, with the SPECIFIED version
  41. # reverse('desecapi:root', request) -> absolute URL, e.g. https://.../api/v1/, with the DEFAULT version
  42. # reverse('v1:root', request) -> absolute URL, e.g. https://.../api/v1/, with the SPECIFIED version
  43. #
  44. # See Also:
  45. # https://github.com/encode/django-rest-framework/issues/5659
  46. # https://github.com/encode/django-rest-framework/issues/3825
  47. #
  48. # Note that from the client's perspective, there is no default version: each request needs to
  49. # specify the version in the request URL.
  50. #
  51. # IMPORTANT: specify default version as the last element in the list
  52. # if no other information is available, the last-specified version will be used as default for reversing URLs
  53. urlpatterns = [
  54. # other available versions in no particular order
  55. path('api/v2/', include('desecapi.urls.version_2', namespace='v2')),
  56. # the DEFAULT version
  57. path('api/v1/', include('desecapi.urls.version_1', namespace='v1')),
  58. ]