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