Setting up Django in a subdirectory

I am trying to set up Django in a subdirectory (running under Apache2 through wsgi), but Django stops recognizing the static URLs.

This is an example url, that gives me a 404: https:/<domain>/<subdirectory>/<appname>/en/static//img/favicon.png

This should map to the filesystem here: /<projectpath>/<appname>/static/<appname>/img/favicon.png

The development server (without a subdirectory) finds the file in the filesystem here: /<appname>/static/<appname>/img/favicon.png

How do I setup django to recognize it's not running at / but at /<subdomain>/?

You can set the STATIC_URL setting [Django-doc] to:

# settings.py

# …

STATIC_URL = '/app_name/static/'

# …

Note however that you use this usually only to generate static URLs, for example with the {% static … %} template tag [Django-doc], since normally static and media files are served by Apache or another webserver.

Вернуться на верх