def clear_messages(request, key=None):
    """Call from a template after rendering messages to clear out the current
    message list.
    """
    if key:
        key = f'messages__{key}'
    else:
        key = 'messages'
    request.session[key]= []
    return ''