WIP: fixing base_url

This commit is contained in:
Amazed 2018-11-30 22:28:26 +01:00
parent bbefbea939
commit af9b1f0c5d
3 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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')),
]

View File

@ -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, }
parse = urllib.parse.urlparse(settings.BASE_URL)
return {'BASE_URL': parse.scheme+"://"+parse.netloc, }