Fix  global name 'media' is not defined