diff --git a/hrss/settings.py b/hrss/settings.py index 8a93130..91014d5 100644 --- a/hrss/settings.py +++ b/hrss/settings.py @@ -27,6 +27,9 @@ DEBUG = True ALLOWED_HOSTS = [] +# Set up your website base URL here, WITHOUT A TRAILING SLASH. +BASE_URL = "http://localhost:8000" + # Application definition diff --git a/hrss/urls.py b/hrss/urls.py index 5f5c976..8918a40 100644 --- a/hrss/urls.py +++ b/hrss/urls.py @@ -16,8 +16,12 @@ Including another URLconf from django.contrib import admin from django.urls import path from django.conf.urls import include, url +from django.conf import settings +import urllib.parse +base_path = urllib.parse.urlparse(settings.BASE_URL).path[1:] + urlpatterns = [ - path('admin/', admin.site.urls), - url(r'', include('web.urls')), + path(base_path+'/admin/', admin.site.urls), + url(base_path+'/' if base_path else '', include('web.urls')), ] diff --git a/web/context_processor.py b/web/context_processor.py index ab06b8c..b8f4102 100644 --- a/web/context_processor.py +++ b/web/context_processor.py @@ -1,16 +1,9 @@ +from django.conf import settings +import urllib.parse + def BASE_URL(request): """ Return a BASE_URL template context for the current request. """ - if request.is_secure(): - scheme = 'https://' - else: - scheme = 'http://' - fullhost = request.get_host() - host = fullhost.split(":")[0] - port = request.get_port() - if port == 80 or port == 443: - base = host - else: - base = host+":"+port - return {'BASE_URL': scheme + base, } \ No newline at end of file + parse = urllib.parse.urlparse(settings.BASE_URL) + return {'BASE_URL': parse.scheme+"://"+parse.netloc, } \ No newline at end of file