urls.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. from django.urls import include, path, re_path
  2. from .views import (
  3. absolute_kwargs_view,
  4. defaults_view,
  5. empty_view,
  6. empty_view_nested_partial,
  7. empty_view_partial,
  8. empty_view_wrapped,
  9. nested_view,
  10. )
  11. other_patterns = [
  12. path("non_path_include/", empty_view, name="non_path_include"),
  13. path("nested_path/", nested_view),
  14. ]
  15. urlpatterns = [
  16. re_path(r"^places/([0-9]+)/$", empty_view, name="places"),
  17. re_path(r"^places?/$", empty_view, name="places?"),
  18. re_path(r"^places+/$", empty_view, name="places+"),
  19. re_path(r"^places*/$", empty_view, name="places*"),
  20. re_path(r"^(?:places/)?$", empty_view, name="places2?"),
  21. re_path(r"^(?:places/)+$", empty_view, name="places2+"),
  22. re_path(r"^(?:places/)*$", empty_view, name="places2*"),
  23. re_path(r"^places/([0-9]+|[a-z_]+)/", empty_view, name="places3"),
  24. re_path(r"^places/(?P<id>[0-9]+)/$", empty_view, name="places4"),
  25. re_path(r"^people/(?P<name>\w+)/$", empty_view, name="people"),
  26. re_path(r"^people/(?:name/)$", empty_view, name="people2"),
  27. re_path(r"^people/(?:name/(\w+)/)?$", empty_view, name="people2a"),
  28. re_path(r"^people/(?P<name>\w+)-(?P=name)/$", empty_view, name="people_backref"),
  29. re_path(r"^optional/(?P<name>.*)/(?:.+/)?", empty_view, name="optional"),
  30. re_path(
  31. r"^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?",
  32. absolute_kwargs_view,
  33. name="named_optional",
  34. ),
  35. re_path(
  36. r"^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?$",
  37. absolute_kwargs_view,
  38. name="named_optional_terminated",
  39. ),
  40. re_path(
  41. r"^nested/noncapture/(?:(?P<p>\w+))$", empty_view, name="nested-noncapture"
  42. ),
  43. re_path(r"^nested/capture/((\w+)/)?$", empty_view, name="nested-capture"),
  44. re_path(
  45. r"^nested/capture/mixed/((?P<p>\w+))$", empty_view, name="nested-mixedcapture"
  46. ),
  47. re_path(
  48. r"^nested/capture/named/(?P<outer>(?P<inner>\w+)/)?$",
  49. empty_view,
  50. name="nested-namedcapture",
  51. ),
  52. re_path(r"^hardcoded/$", empty_view, name="hardcoded"),
  53. re_path(r"^hardcoded/doc\.pdf$", empty_view, name="hardcoded2"),
  54. re_path(r"^people/(?P<state>\w\w)/(?P<name>\w+)/$", empty_view, name="people3"),
  55. re_path(r"^people/(?P<state>\w\w)/(?P<name>[0-9])/$", empty_view, name="people4"),
  56. re_path(r"^people/((?P<state>\w\w)/test)?/(\w+)/$", empty_view, name="people6"),
  57. re_path(r"^character_set/[abcdef0-9]/$", empty_view, name="range"),
  58. re_path(r"^character_set/[\w]/$", empty_view, name="range2"),
  59. re_path(r"^price/\$([0-9]+)/$", empty_view, name="price"),
  60. re_path(r"^price/[$]([0-9]+)/$", empty_view, name="price2"),
  61. re_path(r"^price/[\$]([0-9]+)/$", empty_view, name="price3"),
  62. re_path(
  63. r"^product/(?P<product>\w+)\+\(\$(?P<price>[0-9]+(\.[0-9]+)?)\)/$",
  64. empty_view,
  65. name="product",
  66. ),
  67. re_path(
  68. r"^headlines/(?P<year>[0-9]+)\.(?P<month>[0-9]+)\.(?P<day>[0-9]+)/$",
  69. empty_view,
  70. name="headlines",
  71. ),
  72. re_path(
  73. r"^windows_path/(?P<drive_name>[A-Z]):\\(?P<path>.+)/$",
  74. empty_view,
  75. name="windows",
  76. ),
  77. re_path(r"^special_chars/(?P<chars>.+)/$", empty_view, name="special"),
  78. re_path(r"^resolved/(?P<arg>\d+)/$", empty_view, {"extra": True}, name="resolved"),
  79. re_path(
  80. r"^resolved-overridden/(?P<arg>\d+)/(?P<overridden>\w+)/$",
  81. empty_view,
  82. {"extra": True, "overridden": "default"},
  83. name="resolved-overridden",
  84. ),
  85. re_path(r"^(?P<name>.+)/[0-9]+/$", empty_view, name="mixed"),
  86. re_path(r"^repeats/a{1,2}/$", empty_view, name="repeats"),
  87. re_path(r"^repeats/a{2,4}/$", empty_view, name="repeats2"),
  88. re_path(r"^repeats/a{2}/$", empty_view, name="repeats3"),
  89. re_path(r"^test/1/?", empty_view, name="test"),
  90. re_path(r"^outer/(?P<outer>[0-9]+)/", include("urlpatterns_reverse.included_urls")),
  91. re_path(
  92. r"^outer-no-kwargs/([0-9]+)/",
  93. include("urlpatterns_reverse.included_no_kwargs_urls"),
  94. ),
  95. re_path("", include("urlpatterns_reverse.extra_urls")),
  96. re_path(
  97. r"^lookahead-/(?!not-a-city)(?P<city>[^/]+)/$",
  98. empty_view,
  99. name="lookahead-negative",
  100. ),
  101. re_path(
  102. r"^lookahead\+/(?=a-city)(?P<city>[^/]+)/$",
  103. empty_view,
  104. name="lookahead-positive",
  105. ),
  106. re_path(
  107. r"^lookbehind-/(?P<city>[^/]+)(?<!not-a-city)/$",
  108. empty_view,
  109. name="lookbehind-negative",
  110. ),
  111. re_path(
  112. r"^lookbehind\+/(?P<city>[^/]+)(?<=a-city)/$",
  113. empty_view,
  114. name="lookbehind-positive",
  115. ),
  116. # Partials should be fine.
  117. path("partial/", empty_view_partial, name="partial"),
  118. path("partial_nested/", empty_view_nested_partial, name="partial_nested"),
  119. path("partial_wrapped/", empty_view_wrapped, name="partial_wrapped"),
  120. # This is non-reversible, but we shouldn't blow up when parsing it.
  121. re_path(r"^(?:foo|bar)(\w+)/$", empty_view, name="disjunction"),
  122. path("absolute_arg_view/", absolute_kwargs_view),
  123. # Tests for #13154. Mixed syntax to test both ways of defining URLs.
  124. re_path(
  125. r"^defaults_view1/(?P<arg1>[0-9]+)/$",
  126. defaults_view,
  127. {"arg2": 1},
  128. name="defaults",
  129. ),
  130. re_path(
  131. r"^defaults_view2/(?P<arg1>[0-9]+)/$", defaults_view, {"arg2": 2}, "defaults"
  132. ),
  133. path("includes/", include(other_patterns)),
  134. # Security tests
  135. re_path("(.+)/security/$", empty_view, name="security"),
  136. ]