Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django static_url when script_name set?

Tags:

python

django

So I'm trying to run multiple instances of Django on a server for now, one under /dev/, one under /test/, etc..

The web server is setting the correct SCRIPT_NAME setting and I can serve pages, templates, the whole admin panel fine, except for static assets. Static assets are served by Django using WhiteNoise.

The application is supposed to use the value of SCRIPT_NAME as the static URL, ie all static assets are served from the application root.

So far I've tried the following settings against the admin panel:

# SCRIPT_NAME = '/dev/' Set in env
# URL for static assets should be `/dev/`
STATIC_URL = '/'  # Browser looks for static assets in `/`, drops script_name
STATIC_URL = None # Browser looks for static assets in `/`, drops script_name
STATIC_URL = `/dev/` # Browser looks for static assets in '/dev/dev/`

I'm wondering if I'm missing a setting here or if the problem might be elsewhere. Going by the docs I understand that STATIC_URL = '/' should work?

like image 486
Geotob Avatar asked Sep 19 '25 18:09

Geotob


1 Answers

Finally got a working config for running my app under /dev/:

# SCRIPT_NAME = '/dev/' set from uwsgi, or use FORCE_SCRIPT_NAME
STATIC_URL = '/dev/'
WHITENOISE_STATIC_PREFIX = '/'

This seems to correctly prepend /dev/ to all static URLs, and makes whitenoise serve static assets from that directory (no subdir).

Not sure if this is the correct approach though?

like image 64
Geotob Avatar answered Sep 22 '25 09:09

Geotob