From 62fae6f5270420a1e50f6b76644facd25aff2064 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 24 Oct 2012 16:27:19 +0200 Subject: [PATCH] Fix get_here_url on 404. --- fnpdjango/templatetags/fnp_lang.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fnpdjango/templatetags/fnp_lang.py b/fnpdjango/templatetags/fnp_lang.py index 8eb5194..7f08496 100755 --- a/fnpdjango/templatetags/fnp_lang.py +++ b/fnpdjango/templatetags/fnp_lang.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.core.urlresolvers import resolve, reverse +from django.core.urlresolvers import resolve, reverse, Resolver404 from django import template from django.utils import translation from ..utils.views import get_current_object @@ -32,14 +32,20 @@ def get_here_url(request, lang): with translation.override(lang): url = obj.get_absolute_url() else: - match = resolve(request.get_full_path()) + try: + match = resolve(request.get_full_path()) + except Resolver404: + return None view = match.url_name if view is None: view = match.func if lang is None: lang = translation.get_language() with translation.override(lang): - url = reverse(view, args=match.args, kwargs=match.kwargs) + try: + url = reverse(view, args=match.args, kwargs=match.kwargs) + except Resolver404: + return None return url -- 2.20.1