Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 254687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:52:03+00:00 2026-05-11T21:52:03+00:00

I am trying to write a login_required decorator for the views in a WSGI+Werkzeug

  • 0

I am trying to write a “login_required” decorator for the views in a WSGI+Werkzeug application.

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.

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.

Here’s what I’m trying:

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/<string:name>')
def hello(request, name):
    return render_template('say_hello.html', name=name)

but I get an index out of bounds error trying to call args[0].

Is there any way I can get access to the request argument passed into the “hello” function in the “login_required” decorator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:52:03+00:00Added an answer on May 11, 2026 at 9:52 pm

    The decorator login_required is passed the function (hello in this case).

    So what you want to do is:

    def login_required(f):
        # This function is what we "replace" hello with
        def wrapper(*args, **kw):
            args[0].client_session['test'] = True
            logged_in = 0
            if logged_in:
                return f(*args, **kw)  # Call hello
            else:
                return redirect(url_for('login'))
        return wrapper
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple decorator to check the authentication of a user,
I am trying to write a WSH logon script. Administrators throughout the company need
I am trying write a script where when a user clicks on a link,
I´m trying to write a log system for my CakePHP intranet. What i need
I am trying to write a simple integration test on a Rails 3.1 application
I have several views with @login_required decorator. And I'm going to use django.core.urlresolvers.reverse() function
I'm trying to write an android application that has two main activities: login screen
I'm trying to write a simple smoke test for a web application. The application
So I'm trying to write a php SOAP client that requires the user to
I'm trying to write a POS-style application for a Sheevaplug that does the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.