views:

205

answers:

1

When developing with Django without a web server (serving directly from Django) I have a problem with external urls that lack the domain part and have parameters.

Let's say I'm using a javascript library that does an ajax call to "/prefix/foo/bar?q=1" (the url is not something I can change). It is not a problem for the production server but only a problem when not using a web server. I can redirect by adding the following pattern to my urlpatters:

(r'^prefix/(?P.*)$', 'django.views.generic.simple.redirect_to', {'url': 'htttp://example.com/prefix/%(path)s'}),

but of course %(path)s will only contain "foo/bar" not "foo/bar?q=1".

Is there a way to handle this problem with Django?

+2  A: 

You'll have to write your own redirect:

def redirect_get(request, url, **kwargs):
    if request.META['QUERY_STRING']:
        url += '?%s' % request.META['QUERY_STRING']
    return redirect_to(request, url, **kwargs)
Daniel
Quick answer and to the point. Thanks! Of course, the above-mentioned ajax calls would not work because they would be cross-domain. To remedy that I suppose I should put some proxy code in django.
kmt