title: Bind some arbitrary value to route in Flask
body: <p>How can I elegantly bind some arbitrary value and flask route? Suppose, I want to access this value in my session interface implementation or in <code>before_request</code> hook. </p>
  
  <p>Now I'm doing it in such way:</p>
  
  <pre><code>@app.route('/foo/&lt;bar&gt;', defaults={'_my_val': True}):
  def foo(bar, _my_val):  # this is ugly hack
      pass
  </code></pre>
  
  <p>And access this value through request object like this:</p>
  
  <pre><code>class MyRequest(flask.Request):
      def get_my_val(self):
          return (self.url_rule.defaults or {}).get('_my_val', False)
  </code></pre>
  
  <p>But it looks like a hack.</p>
  
  <p><strong>UPD:</strong> Looks like it can be done by extending <code>werkzeug.routing.Rule</code> class and adding <code>**kwargs</code> to its constructor. Is it ok to override Rule class in flask?</p>