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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:49:39+00:00 2026-05-13T09:49:39+00:00

I have this decorator, used to decorate a django view when I do not

  • 0

I have this decorator, used to decorate a django view when I do not want the view to be executed if the share argument is True (handled by middleware)

class no_share(object):
    def __init__(self, view):
        self.view = view

    def __call__(self, request, *args, **kwargs):
        """Don't let them in if it's shared"""

        if kwargs.get('shared', True):
            from django.http import Http404
            raise Http404('not availiable for sharing')

        return self.view(request, *args, **kwargs)

It currently works like this:

@no_share
def prefs(request, [...])

But I’m wanting to expand the functionality a little bit, so that it will work like this:

@no_share('prefs')
def prefs(request, [...])

My question is how can I modify this decorator class so that it accepts extra arguments?

  • 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-13T09:49:39+00:00Added an answer on May 13, 2026 at 9:49 am

    I hope this article by Bruce Eckel helps.

    Upd:
    According to the article your code will look like this:

    class no_share(object):
        def __init__(self, arg1):
            self.arg1 = arg1
    
        def __call__(self, f):
            """Don't let them in if it's shared"""
    
            # Do something with the argument passed to the decorator.
            print 'Decorator arguments:', self.arg1
    
            def wrapped_f(request, *args, **kwargs):
                if kwargs.get('shared', True):
                    from django.http import Http404
                    raise Http404('not availiable for sharing')
                f(request, *args, **kwargs)            
            return wrapped_f
    

    to be used as desired:

    @no_share('prefs')
    def prefs(request, [...])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm teaching myself Objective-C as a guilty pleasure, if you would. I have a
I have a COM server, implemented in C#. It exposes a class decorated like
Using Microsoft's designer for the Entity Framework (v3.5), I have created an Entity Model
In my application we have a trace logger. We have log statements added at
I have a theme in which there are numerous options, like:- Setting Theme Type
I have a layout based on absolute positioning and a CSS-based menu in the
I'm writing a client/server system. The server has a DAL/BLL design. The client is
A series of applications I'm writing require that the user be able to read
I am using a web application framework (Symfony 1.3.6), which follows the MVC pattern.
jQuery is highly focused on the DOM and provides a nice abstraction around it.

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.