Django Admin - FORCE_SCRIPT_NAME is added twice to the URL when POSTING

I deployed Django to a subdirectory (I do not have full control over the server, so I cannot change the way it is deployed).

I added to my settings:

FORCE_SCRIPT_NAME = '/hub06'
STATIC_URL = FORCE_SCRIPT_NAME + '/static/'

Now, when I go to /admin/hub06, it works correctly, I can log in and view all the admin pages. As soon as I make a request POSTthough (adding a new model), the url is corrupted.

For example, when editing /hub06/admin/myapp/car/1

When I submit the form, it redirects to /hub06/hub06/admin/myapp/car/

Thus, he adds the name of the script twice. This is only done for queries POSTin the Django admin.

+4
source share
2

:

# NB - this setting is required to make the app work correctly when running
# via ProxyPass from Apache. Otherwise CSRF checks and some redirects will not
# work.
USE_X_FORWARDED_HOST = True
0

linux? apache, nginx? , -.

url, /hub06/, settings.py, URL-, LOGIN_URL, STATIC_URL, LOGIN_REDIRECT_URL .., .

, FORCE_SCRIPT_NAME. , settings.py urls.py, , :

from django.conf.urls import patterns, include, url
from django.contrib.auth.views import login
from django.contrib import admin
admin.autodiscover()

urlpatterns2 = patterns('',
    url(r'^$', 'yourapp.views.home', name='Home'),
    url(r'^admin/', include(admin.site.urls)),
)

urlpatterns = patterns('',
    url(r'^hub06/', include(urlpatterns2)),
)

, .

+5

All Articles