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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:50:30+00:00 2026-05-28T13:50:30+00:00

I have the following decorator and view which works fine. Decorator def event_admin_only(func): Checks

  • 0

I have the following decorator and view which works fine.

Decorator

def event_admin_only(func):
    """
    Checks if the current role for the user is an Event Admin or not
    """
    def decorator(request, *args, **kwargs):
        event = get_object_or_404(Event, slug=kwargs['event_slug'])

        allowed_roles = [role[1] for role in Role.ADMIN_ROLES]

        # get user current role
        current_role = request.session.get('current_role')

        if current_role not in allowed_roles:
            url = reverse('no_perms')
            return redirect(url)
        else:       
            return func(request, *args, **kwargs)
    return decorator

View

@event_admin_only
def event_dashboard(request, event_slug):
    pass

But how can I modify my decorator such that it takes in an additional parameter like so:

@event_admin_only(obj1,[...])
def event_dashboard(request, event_slug):
    pass
  • 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-28T13:50:32+00:00Added an answer on May 28, 2026 at 1:50 pm

    You need to wrap the decorator function creation in another function:

    def the_decorator(arg1, arg2):
    
        def _method_wrapper(view_method):
    
            def _arguments_wrapper(request, *args, **kwargs) :
                """
                Wrapper with arguments to invoke the method
                """
    
                #do something with arg1 and arg2
    
                return view_method(request, *args, **kwargs)
    
            return _arguments_wrapper
    
        return _method_wrapper
    

    This can then be called like this:

    @the_decorator("an_argument", "another_argument")
    def event_dashboard(request, event_slug):
    

    I’d recommend the answer from e-satis on this question to understand this: 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

I have the following decorator in my app which checks if the current user
I have the following class which is a decorator for an IDisposable object (I
I have the following style which works as I want it to work: .container
I have the following decorator with parameters: from functools import wraps def pdecor(p): def
I have the following decorator in a base class: class BaseTests(TestCase): @staticmethod def check_time(self,
I have a following decorator: from decorator import decorator def my_decorator(key=None, timeout=None, retry=0): My
I have following script that executes all the .reg files in the current directory.
I have a Django view that receives POSTs which do not need to have
In my template, I have the following: <ul class=tabbed id=network-tabs> {% if user.is_authenticated %}
Let's assume we have a decorator: def decor(function): def result(): printf('decorated') return function() return

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.