Skip to content

Commit

Permalink
Merge pull request #130 from drworm/fix
Browse files Browse the repository at this point in the history
Fixed to work with 404 pages
  • Loading branch information
Frodothedwarf committed Jul 8, 2024
2 parents b6a284e + a739181 commit 16ab62a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions active_link/templatetags/active_link_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ def active_link(
# Can't work without the request object.
return css_inactive_class

if request.resolver_match.kwargs != {}:
# Capture the url kwargs to reverse against
kwargs.update(request.resolver_match.kwargs)
resolver_kwargs = {}
if hasattr(request, "resolver_match") and hasattr(request.resolver_match, "kwargs"):
resolver_kwargs = request.resolver_match.kwargs

kwargs.update(resolver_kwargs)

active = False
views = viewnames.split("||")
request_path = escape_uri_path(request.path)

for viewname in views:
try:
path = reverse(viewname.strip(), args=args, kwargs=kwargs)
except NoReverseMatch:
continue
request_path = escape_uri_path(request.path)

if strict:
active = request_path == path
else:
active = request_path.find(path) == 0
active = request_path.startswith(path) or path.startswith(request_path)
if active:
break

Expand Down

0 comments on commit 16ab62a

Please sign in to comment.