@James Wallace's answer works well if you have control over the web server hosting Django at / someuri. In this configuration, the server will pass the value SCRIPT_NAME in the Django header, which then finds out that it is being served on this subclause.
However, if you do not have control over the external server, you can force Django to accept this value by adding settings.py to the project:
USE_X_FORWARDED_HOST = True FORCE_SCRIPT_NAME = '/someuri'
Subsequently, you may have problems with static files, css, etc. even in the admin application. In the default configuration, they are served by the Django development server unchanged. However, with the above changes, static files will be lost. Assuming that you still want to serve these files through the internal Django development server (and not through an external web server), you need to add settings.py to the project file:
STATIC_SUFFIX = '/static/' STATIC_URL = FORCE_SCRIPT_NAME + STATIC_SUFFIX MEDIA_SUFFIX = '/media/' MEDIA_URL = FORCE_SCRIPT_NAME + MEDIA_SUFFIX
In the same file, you also need to modify the TEMPLATES and add the following:
STATIC_ROOT = os.path.join(BASE_DIR, "static/") TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ STATIC_ROOT ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
Then you will want to collect the static files in the specified directory:
python manage.py collectstatic
or
python3 manage.py collectstatic
The project-level urls.py file should look like this (Django v1.11):
import os from django.conf.urls import url from django.contrib import admin from django.conf.urls.static import static from django.conf import settings from django.views.generic.base import TemplateView urlpatterns = [ url(r'^admin/', admin.site.urls), ] + static(settings.STATIC_SUFFIX, document_root=settings.STATIC_ROOT)
After that, the administration package should work fine, with the appropriate style sheets and everything. The only thing that doesn't seem to work well is the “SITE VIEW” link, as it skips the slash. I did not find a solution for this, but this is probably due to the hacking of the admin application.
In addition, there are various online manuals for installing Django at a subpath. It's messy, but the above avoids the worst headaches.