django template does not like defaultdict, 2 solutions:
1) set default_factory to None
or
2) cast defaultdict to a simpledict
"The template variable resolution algorithm in Django will attempt to resolve new_data.items as new_data['items'] first, which resolves to an empty list when using defaultdict(list)."
 -
                
                https://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict
  
 -
                
                https://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdictHere's my filter code
from django import template
register = template.Library()
@register.filter()
def smooth_timedelta(timedeltaobj):
"""Convert a datetime.timedelta object into Days, Hours, Minutes, Seconds."""
secs = timedeltaobj.total_seconds()
timetot = ""
if secs > 86400: # 60sec  60min  24hrs
days = secs // 86400
timetot += "{} days".format(int(days))
secs = secs - days*86400
if secs > 3600:
    hrs = secs // 3600
    timetot += " {} hours".format(int(hrs))
    secs = secs - hrs*3600
if secs > 60:
    mins = secs // 60
    timetot += " {} minutes".format(int(mins))
    secs = secs - mins*60
if secs > 0:
    timetot += " {} seconds".format(int(secs))
return timetotThen in my template I did
{% load smooth_timedelta %}
{% timedeltaobject|smooth_timedelta %}
 -
                
                https://stackoverflow.com/questions/16348003/displaying-a-timedelta-object-in-a-django-template
  
 -
                
                https://stackoverflow.com/questions/16348003/displaying-a-timedelta-object-in-a-django-templateAnother simple solution would be to write a custom MIDDLEWARE which will give the response to ELB before the ALLOWED_HOSTS is checked. So now you don't have to load ALLOWED_HOSTS dynamically.
The middleware can be as simple as:
project/app/middleware.py
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
class HealthCheckMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.META["PATH_INFO"] == "/ping/":
return HttpResponse("pong")
settings.py
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'app.middleware.HealthCheckMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
...
]
Django Middleware reference https://docs.djangoproject.com/en/dev/topics/http/middleware/
 -
                
                https://stackoverflow.com/questions/35858040/django-allowed-hosts-for-amazon-elb
  
 -
                
                https://stackoverflow.com/questions/35858040/django-allowed-hosts-for-amazon-elbComment passer en prod une app django
 -
                
                http://www.djangobook.com/en/2.0/chapter12.html
  
 -
                
                http://www.djangobook.com/en/2.0/chapter12.html