Ticket #3224: build_url.diff
File build_url.diff, 1.7 KB (added by , 18 years ago) |
---|
-
http/__init__.py
302 302 if not host: 303 303 host = request.META.get('HTTP_HOST', '') 304 304 return host 305 306 def build_url(request, path, host=None): 307 "Builds an absolute URL with the given path." 308 if not host: 309 host = get_host(request) 310 311 if host: 312 newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', host, path) 313 else: 314 newurl = path 315 316 if request.GET: 317 newurl += '?' + request.GET.urlencode() 318 319 return newurl -
middleware/common.py
44 44 raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]) 45 45 if new_url != old_url: 46 46 # Redirect 47 if new_url[0]: 48 newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1]) 49 else: 50 newurl = new_url[1] 51 if request.GET: 52 newurl += '?' + request.GET.urlencode() 47 newurl = http.build_url(request, host=new_url[0], path=new_url[1]) 53 48 return http.HttpResponsePermanentRedirect(newurl) 54 49 55 50 return None