January 9, 2011

Using ProxyPass with django project

Once again I need to postpone my post about django-syncr and youtube since I came across interesting problem recently. Here's the deal : user has his django app running on some server under some link. Application itself is visible under different link. So apache conf got 'ProxyPass' and 'ProxyPassReverse' added. All seemed to work fine apart of links created with '{% url %}' templatetag (and from what I was able to test also get_absolute_urls could cause problems depending on the method used to create them). Url tag was adding original django application name to the link. Because I'm no good in setting apache I've came up with different solution. After skimming through django/template/defaulttags and django/core/urlesolvers I've realized that rewriting both 'reverse' function and 'url' tag would be tedious and probably unnecessary. Instead I've just added this 'try' block that replaces first unwanted occurence of our app name (which is defined in settings under PROJECT_NAME variable) with empty sign to 'url' templatetag and saved it as custom tag named 'urlc'. Not sure if overriding default tags works, gotta check it some day.

                if self.asvar is None:
                    raise e
        #code starts here
            url = url.replace(settings.PROJECT_NAME+'/', '', 1)
        #code ends here    

        if self.asvar:
            context[self.asvar] = url
            return ''

Not sure if it works for OP, but worked at my test config without bigger problems.

No comments:

Post a Comment