title: Python - Get original function arguments in decorator
body: <p>I am trying to write a "login_required" decorator for the views in a WSGI+Werkzeug application.</p>
  
  <p>In order to do this, I need to get at the user's session, which is accessible via the Request object that is passed into the view methods.</p>
  
  <p>I can't figure out how to get at that instance of Request in the decorator, though. I looked at PEP318, specifically the fourth example, but I'm not quite getting it.</p>
  
  <p>Here's what I'm trying:</p>
  
  <pre><code>def login_required(*args, **kw):
      def goto_login(**kw):
          return redirect(url_for('login'))
  
      def decorate(f):
          # args[0] should be request
          args[0].client_session['test'] = True
          logged_in = 0
          if logged_in:
              return f
          else:
              return goto_login
      return decorate
  
  
  @login_required()
  @expose('/hello/&lt;string:name&gt;')
  def hello(request, name):
      return render_template('say_hello.html', name=name)
  </code></pre>
  
  <p>but I get an index out of bounds error trying to call <code>args[0]</code>.</p>
  
  <p>Is there any way I can get access to the request argument passed into the "hello" function in the "login_required" decorator?</p>