2018-12-08 06:52:28 +08:00
|
|
|
from django.urls import include, path, re_path
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2014-08-12 22:54:42 +08:00
|
|
|
from .views import (
|
2016-01-06 05:47:48 +08:00
|
|
|
absolute_kwargs_view,
|
|
|
|
defaults_view,
|
|
|
|
empty_view,
|
|
|
|
empty_view_nested_partial,
|
|
|
|
empty_view_partial,
|
|
|
|
empty_view_wrapped,
|
|
|
|
nested_view,
|
2014-08-12 22:54:42 +08:00
|
|
|
)
|
2011-10-14 05:34:56 +08:00
|
|
|
|
2014-04-02 08:46:34 +08:00
|
|
|
other_patterns = [
|
2018-12-08 06:52:28 +08:00
|
|
|
path("non_path_include/", empty_view, name="non_path_include"),
|
|
|
|
path("nested_path/", nested_view),
|
2014-04-02 08:46:34 +08:00
|
|
|
]
|
|
|
|
|
2015-08-17 22:45:00 +08:00
|
|
|
urlpatterns = [
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(r"^places/([0-9]+)/$", empty_view, name="places"),
|
|
|
|
re_path(r"^places?/$", empty_view, name="places?"),
|
|
|
|
re_path(r"^places+/$", empty_view, name="places+"),
|
|
|
|
re_path(r"^places*/$", empty_view, name="places*"),
|
|
|
|
re_path(r"^(?:places/)?$", empty_view, name="places2?"),
|
|
|
|
re_path(r"^(?:places/)+$", empty_view, name="places2+"),
|
|
|
|
re_path(r"^(?:places/)*$", empty_view, name="places2*"),
|
|
|
|
re_path(r"^places/([0-9]+|[a-z_]+)/", empty_view, name="places3"),
|
|
|
|
re_path(r"^places/(?P<id>[0-9]+)/$", empty_view, name="places4"),
|
|
|
|
re_path(r"^people/(?P<name>\w+)/$", empty_view, name="people"),
|
|
|
|
re_path(r"^people/(?:name/)$", empty_view, name="people2"),
|
|
|
|
re_path(r"^people/(?:name/(\w+)/)?$", empty_view, name="people2a"),
|
|
|
|
re_path(r"^people/(?P<name>\w+)-(?P=name)/$", empty_view, name="people_backref"),
|
|
|
|
re_path(r"^optional/(?P<name>.*)/(?:.+/)?", empty_view, name="optional"),
|
|
|
|
re_path(
|
|
|
|
r"^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?",
|
|
|
|
absolute_kwargs_view,
|
|
|
|
name="named_optional",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?$",
|
|
|
|
absolute_kwargs_view,
|
|
|
|
name="named_optional_terminated",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^nested/noncapture/(?:(?P<p>\w+))$", empty_view, name="nested-noncapture"
|
2022-02-04 03:24:19 +08:00
|
|
|
),
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(r"^nested/capture/((\w+)/)?$", empty_view, name="nested-capture"),
|
|
|
|
re_path(
|
|
|
|
r"^nested/capture/mixed/((?P<p>\w+))$", empty_view, name="nested-mixedcapture"
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^nested/capture/named/(?P<outer>(?P<inner>\w+)/)?$",
|
|
|
|
empty_view,
|
|
|
|
name="nested-namedcapture",
|
|
|
|
),
|
|
|
|
re_path(r"^hardcoded/$", empty_view, name="hardcoded"),
|
|
|
|
re_path(r"^hardcoded/doc\.pdf$", empty_view, name="hardcoded2"),
|
|
|
|
re_path(r"^people/(?P<state>\w\w)/(?P<name>\w+)/$", empty_view, name="people3"),
|
|
|
|
re_path(r"^people/(?P<state>\w\w)/(?P<name>[0-9])/$", empty_view, name="people4"),
|
|
|
|
re_path(r"^people/((?P<state>\w\w)/test)?/(\w+)/$", empty_view, name="people6"),
|
|
|
|
re_path(r"^character_set/[abcdef0-9]/$", empty_view, name="range"),
|
|
|
|
re_path(r"^character_set/[\w]/$", empty_view, name="range2"),
|
|
|
|
re_path(r"^price/\$([0-9]+)/$", empty_view, name="price"),
|
|
|
|
re_path(r"^price/[$]([0-9]+)/$", empty_view, name="price2"),
|
|
|
|
re_path(r"^price/[\$]([0-9]+)/$", empty_view, name="price3"),
|
|
|
|
re_path(
|
|
|
|
r"^product/(?P<product>\w+)\+\(\$(?P<price>[0-9]+(\.[0-9]+)?)\)/$",
|
|
|
|
empty_view,
|
|
|
|
name="product",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^headlines/(?P<year>[0-9]+)\.(?P<month>[0-9]+)\.(?P<day>[0-9]+)/$",
|
|
|
|
empty_view,
|
|
|
|
name="headlines",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^windows_path/(?P<drive_name>[A-Z]):\\(?P<path>.+)/$",
|
|
|
|
empty_view,
|
|
|
|
name="windows",
|
2022-02-04 03:24:19 +08:00
|
|
|
),
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(r"^special_chars/(?P<chars>.+)/$", empty_view, name="special"),
|
2022-03-28 23:56:20 +08:00
|
|
|
re_path(r"^resolved/(?P<arg>\d+)/$", empty_view, {"extra": True}, name="resolved"),
|
|
|
|
re_path(
|
|
|
|
r"^resolved-overridden/(?P<arg>\d+)/(?P<overridden>\w+)/$",
|
|
|
|
empty_view,
|
|
|
|
{"extra": True, "overridden": "default"},
|
|
|
|
name="resolved-overridden",
|
|
|
|
),
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(r"^(?P<name>.+)/[0-9]+/$", empty_view, name="mixed"),
|
|
|
|
re_path(r"^repeats/a{1,2}/$", empty_view, name="repeats"),
|
|
|
|
re_path(r"^repeats/a{2,4}/$", empty_view, name="repeats2"),
|
|
|
|
re_path(r"^repeats/a{2}/$", empty_view, name="repeats3"),
|
|
|
|
re_path(r"^test/1/?", empty_view, name="test"),
|
|
|
|
re_path(r"^outer/(?P<outer>[0-9]+)/", include("urlpatterns_reverse.included_urls")),
|
|
|
|
re_path(
|
|
|
|
r"^outer-no-kwargs/([0-9]+)/",
|
|
|
|
include("urlpatterns_reverse.included_no_kwargs_urls"),
|
2022-02-04 03:24:19 +08:00
|
|
|
),
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path("", include("urlpatterns_reverse.extra_urls")),
|
|
|
|
re_path(
|
|
|
|
r"^lookahead-/(?!not-a-city)(?P<city>[^/]+)/$",
|
|
|
|
empty_view,
|
|
|
|
name="lookahead-negative",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^lookahead\+/(?=a-city)(?P<city>[^/]+)/$",
|
|
|
|
empty_view,
|
|
|
|
name="lookahead-positive",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^lookbehind-/(?P<city>[^/]+)(?<!not-a-city)/$",
|
|
|
|
empty_view,
|
|
|
|
name="lookbehind-negative",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^lookbehind\+/(?P<city>[^/]+)(?<=a-city)/$",
|
|
|
|
empty_view,
|
|
|
|
name="lookbehind-positive",
|
2022-02-04 03:24:19 +08:00
|
|
|
),
|
2015-08-17 22:45:00 +08:00
|
|
|
# Partials should be fine.
|
2018-12-08 06:52:28 +08:00
|
|
|
path("partial/", empty_view_partial, name="partial"),
|
|
|
|
path("partial_nested/", empty_view_nested_partial, name="partial_nested"),
|
|
|
|
path("partial_wrapped/", empty_view_wrapped, name="partial_wrapped"),
|
2015-08-17 22:45:00 +08:00
|
|
|
# This is non-reversible, but we shouldn't blow up when parsing it.
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(r"^(?:foo|bar)(\w+)/$", empty_view, name="disjunction"),
|
|
|
|
path("absolute_arg_view/", absolute_kwargs_view),
|
2015-08-17 22:45:00 +08:00
|
|
|
# Tests for #13154. Mixed syntax to test both ways of defining URLs.
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path(
|
|
|
|
r"^defaults_view1/(?P<arg1>[0-9]+)/$",
|
|
|
|
defaults_view,
|
|
|
|
{"arg2": 1},
|
|
|
|
name="defaults",
|
|
|
|
),
|
|
|
|
re_path(
|
|
|
|
r"^defaults_view2/(?P<arg1>[0-9]+)/$", defaults_view, {"arg2": 2}, "defaults"
|
2022-02-04 03:24:19 +08:00
|
|
|
),
|
2018-12-08 06:52:28 +08:00
|
|
|
path("includes/", include(other_patterns)),
|
2015-08-17 22:45:00 +08:00
|
|
|
# Security tests
|
2018-12-08 06:52:28 +08:00
|
|
|
re_path("(.+)/security/$", empty_view, name="security"),
|
2015-08-17 22:45:00 +08:00
|
|
|
]
|