re_path() and regex patterns
standardintermediatere_path() matches a URL with a regular expression instead of path()'s converter syntax — named groups ((?P<name>...)) capture values, but every captured value arrives as a plain string, unlike path()'s automatic int/slug/uuid conversion.
Think of it as
path() is a fill-in-the-blank form with typed fields; re_path() is a blank sheet of paper where you write the whole pattern yourself. re_path() can express anything a regex can, including patterns path() has no converter for — but it gives nothing back for free: every captured group is a string, and getting the pattern wrong fails silently by just not matching, not by raising an error.
What we're doing: Match a URL pattern path() cannot express directly — two segments that must both be four-digit years in a specific order.
- 4
- Both start_year and end_year are captured as strings and passed as keyword arguments to date_range_report — the view itself is responsible for converting and validating them as integers.
Why this works: No single path() converter can express "two four-digit numbers separated by a literal hyphen" as one segment — path()'s converters each match one segment in isolation, while a regex can constrain the whole pattern, hyphen included, in one expression.
Forgetting that re_path() captures always arrive as strings
Wrong
Better
What you see: A comparison or arithmetic operation against the captured value either raises a TypeError or, for a string-vs-int comparison, silently produces the wrong boolean result.
Why: re_path() has no equivalent of path()'s <int:name> converter — every named group it captures is handed to the view as a plain str, regardless of what the regex matched, so any numeric use requires an explicit int()/conversion the view must do itself.
path() vs re_path() for the same route
Together
Remember: re_path() matches with a regex and captures everything as a string — reach for it only when path()'s five converters genuinely can't express the pattern.
See also: url configuration · url namespaces

