Skip to content

Commit e7e14f2

Browse files
committed
Allow 'settings.PROJECT_HOME_NAMESPACE' to be an actual URL, rather than just an internal namespace
1 parent bca9f54 commit e7e14f2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

project_home_tags/templatetags/project_home.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django import template
44
from django import VERSION as DJANGO_VERSION
55
from django.conf import settings
6+
from django.core.exceptions import ValidationError
7+
from django.core.validators import URLValidator
68
from django.utils.html import format_html
79

810
if DJANGO_VERSION < (1, 10):
@@ -20,10 +22,18 @@ def home_url():
2022
2123
Returns None if PROJECT_HOME_NAMESPACE is not defined in settings.
2224
"""
25+
global home_namespace
2326
try:
2427
return reverse(home_namespace)
2528
except Exception:
26-
return None
29+
try:
30+
validate_url = URLValidator()
31+
if '://' not in home_namespace:
32+
home_namespace = 'http://' + home_namespace
33+
validate_url(home_namespace)
34+
return(home_namespace)
35+
except ValidationError:
36+
return None
2737

2838

2939
def silence_without_namespace(f):

0 commit comments

Comments
 (0)