Skip to content

Instantly share code, notes, and snippets.

@wonderbeyond
Last active May 25, 2023 17:53
Show Gist options
  • Save wonderbeyond/556b661cfec84ee2fa0e08fbacc59f44 to your computer and use it in GitHub Desktop.
Save wonderbeyond/556b661cfec84ee2fa0e08fbacc59f44 to your computer and use it in GitHub Desktop.
Deploy Django site under a sub-path (virtual location) of a shared domain

Your Django project maybe required to hosted under a shared domain, but use a separate subpath.

To make django generate right URLs and avoid cookie conflicts, do settings below:

FORCE_SCRIPT_NAME = '/A-site/'
CSRF_COOKIE_PATH = LANGUAGE_COOKIE_PATH = SESSION_COOKIE_PATH = FORCE_SCRIPT_NAME

LOGIN_URL = '{0}api-auth/login/'.format(FORCE_SCRIPT_NAME)
LOGOUT_URL = '{0}api-auth/logout/'.format(FORCE_SCRIPT_NAME)

SPECTACULAR_SETTINGS["SERVERS"] = [{"url": FORCE_SCRIPT_NAME}]  # work with drf-spectacular

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment