1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Seems like a design flaw in Django.
It turns out that Django 1.4 added something to help with this. See docs.djangoproject.com/en/dev/ref/urlresolvers/#reverse-lazy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.