2
0

namespace_urls.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from django.urls import include, path, re_path
  2. from . import views
  3. from .utils import URLObject
  4. testobj1 = URLObject("testapp", "test-ns1")
  5. testobj2 = URLObject("testapp", "test-ns2")
  6. default_testobj = URLObject("testapp", "testapp")
  7. otherobj1 = URLObject("nodefault", "other-ns1")
  8. otherobj2 = URLObject("nodefault", "other-ns2")
  9. newappobj1 = URLObject("newapp")
  10. app_name = "namespace_urls"
  11. urlpatterns = [
  12. path("normal/", views.empty_view, name="normal-view"),
  13. re_path(
  14. r"^normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$",
  15. views.empty_view,
  16. name="normal-view",
  17. ),
  18. path("resolver_match/", views.pass_resolver_match_view, name="test-resolver-match"),
  19. re_path(r"^\+\\\$\*/$", views.empty_view, name="special-view"),
  20. re_path(
  21. r"^mixed_args/([0-9]+)/(?P<arg2>[0-9]+)/$",
  22. views.empty_view,
  23. {"extra": True},
  24. name="mixed-args",
  25. ),
  26. re_path(r"^no_kwargs/([0-9]+)/([0-9]+)/$", views.empty_view, name="no-kwargs"),
  27. re_path(
  28. r"^view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$",
  29. views.view_class_instance,
  30. name="view-class",
  31. ),
  32. re_path(r"^unnamed/normal/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$", views.empty_view),
  33. re_path(
  34. r"^unnamed/view_class/(?P<arg1>[0-9]+)/(?P<arg2>[0-9]+)/$",
  35. views.view_class_instance,
  36. ),
  37. path("test1/", include(*testobj1.urls)),
  38. path("test2/", include(*testobj2.urls)),
  39. path("default/", include(*default_testobj.urls)),
  40. path("other1/", include(*otherobj1.urls)),
  41. re_path(r"^other[246]/", include(*otherobj2.urls)),
  42. path("newapp1/", include(newappobj1.app_urls, "new-ns1")),
  43. path("new-default/", include(newappobj1.app_urls)),
  44. re_path(
  45. r"^app-included[135]/",
  46. include("urlpatterns_reverse.included_app_urls", namespace="app-ns1"),
  47. ),
  48. path(
  49. "app-included2/",
  50. include("urlpatterns_reverse.included_app_urls", namespace="app-ns2"),
  51. ),
  52. re_path(
  53. r"^ns-included[135]/",
  54. include("urlpatterns_reverse.included_namespace_urls", namespace="inc-ns1"),
  55. ),
  56. path(
  57. "ns-included2/",
  58. include("urlpatterns_reverse.included_namespace_urls", namespace="inc-ns2"),
  59. ),
  60. path(
  61. "app-included/",
  62. include("urlpatterns_reverse.included_namespace_urls", "inc-app"),
  63. ),
  64. path("included/", include("urlpatterns_reverse.included_namespace_urls")),
  65. re_path(
  66. r"^inc(?P<outer>[0-9]+)/",
  67. include(
  68. ("urlpatterns_reverse.included_urls", "included_urls"), namespace="inc-ns5"
  69. ),
  70. ),
  71. re_path(
  72. r"^included/([0-9]+)/", include("urlpatterns_reverse.included_namespace_urls")
  73. ),
  74. re_path(
  75. r"^ns-outer/(?P<outer>[0-9]+)/",
  76. include("urlpatterns_reverse.included_namespace_urls", namespace="inc-outer"),
  77. ),
  78. re_path(
  79. r"^\+\\\$\*/",
  80. include("urlpatterns_reverse.namespace_urls", namespace="special"),
  81. ),
  82. ]