code: async def message_data(request):
      
      messages = []
      # {% if database.is_none %}
      if request.app['settings'].MESSAGE_FILE.exists():
          # read the message file, process it and populate the "messages" list
          with request.app['settings'].MESSAGE_FILE.open() as msg_file:
              for line in msg_file:
                  if not line:
                      # ignore blank lines eg. end of file
                      continue
                  # split the line into it constituent parts, see process_form above
                  username, ts, message = line.split('|', 2)
                  # parse the datetime string and render it in a more readable format.
                  ts = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.strptime(ts, '%Y-%m-%dT%H:%M:%S.%f'))
                  messages.append({'username': username, 'timestamp': ts, 'message': message})
          messages.reverse()
      # {% elif database.is_pg_sqlalchemy %}
  
      async with request.app['pg_engine'].acquire() as conn:
          async for row in conn.execute(sa_messages.select().order_by(sa_messages.c.timestamp.desc())):
              ts = '{:%Y-%m-%d %H:%M:%S}'.format(row.timestamp)
              messages.append({'username': row.username, 'timestamp': ts, 'message': row.message})
      # {% endif %}
      return json_response(messages)
docs: As an example of aiohttp providing a non-html response, we load the actual messages for the "messages" view above
      via ajax using this endpoint to get data. see static/message_display.js for details of rendering.