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