Here are the examples of the python api django.http.get_host taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
def get_url_host(request):
if request.is_secure():
protocol = 'https'
else:
protocol = 'http'
host = escape(get_host(request))
return '%s://%s' % (protocol, host)
3
View Complete Implementation : sslmiddleware.py
Copyright BSD 2-Clause "Simplified" License
Author : evrenesat
Copyright BSD 2-Clause "Simplified" License
Author : evrenesat
def _redirect(self, request, secure):
protocol = secure and "https" or "http"
host = get_host(request)
# if secure:
# host = getattr(settings, 'SSL_HOST', get_host(request))
# else:
# host = getattr(settings, 'HTTP_HOST', get_host(request))
newurl = "%s://%s%s" % (protocol,host,request.get_full_path())
if settings.DEBUG and request.method == 'POST':
raise RuntimeError, \
"""Django can't perform a SSL redirect while maintaining POST data.
Please structure your views so that redirects only occur during GETs."""
return HttpResponseRedirect(newurl)