Add support for context path (#313)

* Add support for context path

add an optional environment variable: LD_CONTEXT_PATH

* Fix for pull request code review comments

Co-authored-by: s2marine <s2marine@gmail.com>
This commit is contained in:
s2marine
2022-08-07 18:41:11 +08:00
committed by GitHub
parent eadae32eb3
commit 8053468ca5
8 changed files with 81 additions and 7 deletions

View File

@@ -107,9 +107,12 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
LOGIN_URL = '/login'
LOGIN_REDIRECT_URL = '/bookmarks'
LOGOUT_REDIRECT_URL = '/login'
# Website context path.
LD_CONTEXT_PATH = os.getenv('LD_CONTEXT_PATH', '')
LOGIN_URL = '/' + LD_CONTEXT_PATH + 'login'
LOGIN_REDIRECT_URL = '/' + LD_CONTEXT_PATH + 'bookmarks'
LOGOUT_REDIRECT_URL = '/' + LD_CONTEXT_PATH + 'login'
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
@@ -127,7 +130,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_URL = '/' + LD_CONTEXT_PATH + 'static/'
# Collect static files in static folder
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

View File

@@ -13,6 +13,7 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib.auth import views as auth_views
from django.urls import path, include
@@ -30,6 +31,9 @@ urlpatterns = [
path('', include('bookmarks.urls')),
]
if settings.LD_CONTEXT_PATH:
urlpatterns = [path(settings.LD_CONTEXT_PATH, include(urlpatterns))]
if DEBUG:
import debug_toolbar