title: In Flask, is it there a way to run some code before every view?
body: <p>I want to clean the session flash with get_flashed_messages(), before the code of every view gets executed. That's because flash is persistent in the session, which is very unfortunate (if the flashed messages are not printed in the authentication procedure, for example, they get all printed at once in the first page that uses the layout).</p>
  
  <p>So, I wanted to run code before every view in the application to clean the session flashed messages.</p>
  
  <p>Functions like before_request or before_app_request won't do it right, because they get executed many times during the request (they are executed for every template or static file being uploaded), and this erases the messages which are flashed inside the view code (I just want to erase the persisted messages from other views, before the current view starts running).</p>
  
  <p>Simply, I want some code to run once, and only once, before every view function is called.</p>
  
  <p>Is this possible in Flask?</p>