rluba
rluba

Reputation: 2044

Django+WSGI: Use app at subpath without changes

I'd like to serve a Django application from a subdirectory (for example http://www.stackoverflow.com/django_app/).

I've set up mod_wsgi to serve the page via

WSGIScriptAlias /django_app PATH_TO_DJANGO/wsgi.py

How can I specify settings like LOGIN_URL, STATIC_URL, MEDIA_URL, etc. so Django respects the relative path?

If set STATIC_URL it to "/static/" it tries to reference resources at http://www.stackoverflow.com/static/ instead of http://www.stackoverflow.com/django_app/static/.

But if I set it to "static" (without a leading slash) it is interpreted relative to any URL which is also wrong. For example, the admin page at

http://www.stackoverflow.com/django_app/admin/

tries to load the files from

http://www.stackoverflow.com/django_app/admin/static/

I haven't found a way to tell Django to use http://www.stackoverflow.com/django_app/static without explicitly hardcoding the prefix /django_app within the settings (which IMHO violates the DRY principle because it is already specified in the mod_wsgi-config). It also prohibits serving the same project under different URLs without modifying the project, which seems odd.

Upvotes: 1

Views: 281

Answers (1)

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

There is no way for it to be automatic. The URLs in those few variables, and LOGOUT_URL, are not automatically prefixed with the SCRIPT_NAME which is passed in with scripts and which identifies the mount point.

Upvotes: 1

Related Questions