1

I have a django app running on http://djangohost/appaddress. I'd like the project to be available at http://differentaddress/app . Currently I'm able to run app at the desired address but using {% url %} templatetags gives me improper address in the form http://differentaddress/app/appaddress. Also when I go to django app address directly all {% url %} links are in the form http://djangohost/app/appadress How can I change this ? I have these entrances in apache conf :

ProxyPass  /app/  http://djangohost/appaddress/
ProxyPassReverse  /app/ http://djangohost/appaddress/
1
  • 1
    How are you actually running Django? mod_python, mod_wsgi? Commented Jan 7, 2011 at 19:04

3 Answers 3

1

You'll probably have to tell Django where it is running by manipulating SCRIPT_NAME

http://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#force-script-name

Or, if you want to keep things within Apache, you may give a try to mod_proxy_html - disclaimer: haven't used it myself, but it does claim to rewrite links in HTML pages

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

Comments

0

Maybe not a proper solution but still some workaround for the problem without interfering with apache's settings. Tested with mod_msgi and it works like a charm. Here's the link : http://fromzerotocodehero.blogspot.com/2011/01/using-proxypass-with-django-project.html . Basically I've overriden built in url function here creating custom urlc temlpatetag. In tag's code I've added line replacing first occurence of unwanted app name with empty sign.

Comments

0

So you want to "mount" a Django site on a sub URL path? I already tried this with Apache and mod_proxy, and it was kind of a nightmare to find out. Here's what I have come up with (probably not complete or perfect):

# In your scenario
FORCE_SCRIPT_NAME = "/app/"

# End of settings
_prefix = (FORCE_SCRIPT_NAME or "")
LOGIN_URL          = _prefix + LOGIN_URL
LOGIN_REDIRECT_URL = _prefix + LOGIN_REDIRECT_URL
LOGOUT_URL         = _prefix + LOGOUT_URL
ADMIN_MEDIA_PREFIX = _prefix + ADMIN_MEDIA_PREFIX

Obviously, this prepends "/app/" to the most important hardcoded site URLs, plus it sets FORCE_SCRIPT_NAME to ensure that {% url something %} will result in an absolute URL of "/app/something", for instance.

This worked for me using mod_wsgi for the Django site and ProxyPass/ProxyPassReverse for the "mounting". Try it out and give me feedback, I'm interested whether this is a general solution.

2 Comments

FORCE_SCRIPT_NAME should never be needed for mod_wsgi. If the Django was on a backend Apache, then it simply should be mounted at the same sub URL on the backend server as it is being published at via the front end web server. The login URL adjustments will still be needed though.
@Graham: Well, I tried it some weeks ago and ran into trouble. As said, I'm using mod_wsgi (à la WSGIScriptAlias /app /path/to/wsgi.app). If I remember correctly, the problem was with redirects (e.g. HTTP 302). I guess, by "backend Apache" you mean a second Apache where the site is mounted on "/" (with the first Apache ProxyPass-ing to the backend server)?

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.