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

  • Home
  • SEARCH
  • 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 4171030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:24:06+00:00 2026-05-21T00:24:06+00:00

My question is a general one, but specifically my application is the login_required decorator

  • 0

My question is a general one, but specifically my application is the login_required decorator for Django.

I’m curious if there is a way to check if a view/function has a specific decorator (in this case the login_required decorator)

I am redirecting after logging a user out, and I want to redirect to the main page if the page they are currently on has the login_required decorator. My searches have yielded no results so far.

  • 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-21T00:24:06+00:00Added an answer on May 21, 2026 at 12:24 am

    Build your own login_required decorator and have it mark the function as decorated–probably the best place to mark it would be in the func_dict.

    from django.contrib.auth.decorators import login_required as django_l_r
    
    # Here you're defining your own decorator called `login_required`
    # it uses Django's built in `login_required` decorator
    def login_required(func):
        decorated_func = django_l_r(func)
        decorated_func.func_dict['login_is_required'] = True
        return decorated_func
    
    @login_required # Your decorator
    def authenticatedd_view(request):
        pass
    
    def unauthenticated_view(request):
        pass
    

    Now you can check to see if a view was decorated like this…

    # Assume `a_view` is view function
    >>> a_view.func_dict.get('login_is_required',False)
    

    If you’re confused about Python decorators see this SO question/answer: How to make a chain of function decorators?

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

Sidebar

Related Questions

(Note: I'm using jQuery below, but the question is really a general JavaScript one.)
Edit: There was some confusion, but I want to ask a general question about
This question is closely related to this one but i think is more general.
General question about java servlets and the best way to handle requests. If I
This is a general question about MVC as a pattern, but in this case
I have a general question that is rather open-ended (i.e. depends on platform, application
This is specifically about GWT's RequestBuilder, but should apply to general XHR as well.
I have one question but it can probably be answered by one of several
This question is a general one, and I've already posted a version of it
This is a bit of a general question, but I will give a specific

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.