I have deployed Django to a sub directory (I don't have full control over the server so can't change the way it's deployed).
I added to my settings:
FORCE_SCRIPT_NAME = '/hub06'
STATIC_URL = FORCE_SCRIPT_NAME + '/static/'
Now when I go to /admin/hub06
, it's working properly, I can login and browse all admin pages. As soon as I do a POST
request though (adding a new model), the URL gets corrupted.
For example, when editing /hub06/admin/myapp/car/1
When I submit the form, it redirects to /hub06/hub06/admin/myapp/car/
So it adds script name twice. This is only for POST
requests in Django admin.
Is this a linux host? is it running apache, nginx? It all depends on how your web server is configured.
If you really must have a url prefix like /hub06/
then you will need to update any settings in settings.py that return a url such as LOGIN_URL
, STATIC_URL
, LOGIN_REDIRECT_URL
etc to contain the prefix.
I don't think you need to use FORCE_SCRIPT_NAME
. Comment that bit out in the settings.py
and update urls.py
to add the following for example:
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)),
)
Let me know how you go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With