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 6106021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:02:06+00:00 2026-05-23T14:02:06+00:00

I have the following view function: def gettingstarted_info(request): First page of gettingstarted after Registration.

  • 0

I have the following view function:

def gettingstarted_info(request): 
    """
    First page of gettingstarted after Registration.
    """
    if request.user.is_authenticated():
        if request.user.get_profile().getting_started_boolean: 
             return redirect('/home/')                       
        else:
            user = request.user
    else:
        username = request.session.get('username', False)                                                   
        if not username:
            return redirect('/login')                
        else:
            user = User.objects.get(email=username)  
    # the main part of the view function #

I would like to convert the first part of the view function into an @ decorator, so I could have something like —

@gettingstarted_dispatch
def getting_started_info(request):
    # the main part of the view function

I took a look at the docs on the decorator function but was having a bit of difficulty converting the function so I could use it as an @ decorator. The decorator should filter out unauthorized individuals and return the user variable (note this is not the same as request.user). How would I do this? Thank you.

  • 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-23T14:02:06+00:00Added an answer on May 23, 2026 at 2:02 pm

    I think this function should do the trick for you. 🙂

    def gettingstarted_dispatch(f):
        def wrap(request, *args, **kwargs):
            if request.user.is_authenticated():
                if request.user.get_profile().getting_started_boolean:
                    return redirect('/home/')
                else:
                    user = request.user
            else:
                username = request.session.get('username', False)
                if not username:
                    return redirect('/login')
                else:
                    user = User.objects.get(email=username)
            kwargs['user'] = user
            return f(request, *args, **kwargs)
        return wrap
    

    The function passes the user variable as the user keyword arg.

    Alternatively, if you prefer, user as the second arg…

                else:
                    user = User.objects.get(email=username)
            return f(request, user, *args, **kwargs)
        return wrap
    

    Also, here’s a really nice in depth tutorial on how to do decorators. 🙂

    (Part I) http://www.artima.com/weblogs/viewpost.jsp?thread=240808
    (Part II) http://www.artima.com/weblogs/viewpost.jsp?thread=240845
    (Part III) http://www.artima.com/weblogs/viewpost.jsp?thread=241209

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view function in activities.views : def activity_thumbnail(request, id): pass I'm
I have written a function having the following signature: def action_handler(request, model): This action_handler
I have the following view model which contains an array of elements function ReservationsViewModel()
i have the following Jquery function inside my view:- <script type=text/javascript> $(document).ready(function () {
I have a view function that allows a user to Add / Edit /
The following in part of my view file def user_detail(request, username, template_name='auth/user_detail.html', extra_context=None): context
In my controller/request-handler, I have the following code: def monkey(self, **kwargs): cherrypy.response.headers['Content-Type'] = application/json
I have following view <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <h2>Tables <%=ViewData[RetriverName] %></h2> <%using (Html.BeginForm(ResfreshSelectedTables, Home))
In a branch spec, I have the following view: //depot/dev/t/a/g/... //depot/dev/t/r/g/... -//depot/dev/t/a/g/p/o*/... //depot/dev/t/r/g/p/... Perforce
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.