context_processors.py 405 B

12345678910111213141516
  1. from django.conf import settings
  2. def site_address(request):
  3. if request.is_secure():
  4. site_protocol = 'https'
  5. address_template = 'https://%s'
  6. else:
  7. site_protocol = 'http'
  8. address_template = 'http://%s'
  9. return {
  10. 'SITE_PROTOCOL': site_protocol,
  11. 'SITE_HOST': request.get_host(),
  12. 'SITE_ADDRESS': address_template % request.get_host()
  13. }