def convert_to_http_date(dt):
 if timezone.is_naive(dt):
  default_timezone = timezone.get_default_timezone()
  dt = timezone.make_aware(dt, default_timezone)
 utc_dt = dt.astimezone(timezone.utc)
 epoch_dt = calendar.timegm(utc_dt.utctimetuple())
 return http_date(epoch_dt)

def convert_to_http_date ( dt ) : if timezone . is_naive ( dt ) : default_timezone = timezone . get_default_timezone ( ) dt = timezone . make_aware ( dt , default_timezone ) utc_dt = dt . astimezone ( timezone . utc ) epoch_dt = calendar . timegm ( utc_dt . utctimetuple ( ) ) return http_date ( epoch_dt )
given a timezone naive or aware datetime return the http date formatted string to be used in http response headers .