Does django take SCRIPT_NAME into account when using the default LOGIN_URL

I am using Django 1.0.2 and trying to figure out how to get @login_required to work properly.

When I use the built-in server, it redirects to the default login_url or my LOGIN_URL, as defined in settings.py, as expected.

It’s not clear to me how to deploy a server where my site is not at the root. In my templates, I use the url template tag, and in the views I can access request.META ['SCRIPT_NAME'], but for some reason it doesn't seem to apply to the LOGIN_URL used.

What am I missing?

Thank.

+3
source share
1 answer

, FORCE_SCRIPT_NAME, script, . URL / :

# This is needed because we're running the app in non-root directory of web server
FORCE_SCRIPT_NAME = '/myapp.cgi/'

LOGIN_URL = FORCE_SCRIPT_NAME + 'accounts/login/'
LOGOUT_URL = FORCE_SCRIPT_NAME + 'accounts/logout/'

: https://docs.djangoproject.com/en/dev/ref/settings/#force-script-name

+2

Source: https://habr.com/ru/post/1742687/


All Articles