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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:27:07+00:00 2026-06-16T11:27:07+00:00

Iam using django decorators in my project. Iam using multiple views with arguments and

  • 0

Iam using django decorators in my project.
Iam using multiple views with arguments and i need to call 1 decorator.

I want only one view to call with its arguments once. But the decorators giving the values of every views wherever i used the decorator.

I want the argument belong to the particular views which i called.

My views and decorator as:

def d(msg='my default message'):
    def decorator(func):
        print msg
        def newfn(request, **kwargs):
            return func(request, **kwargs)
        return newfn
    return decorator

@d('This is working')
def company_add(request):
   return ...

@d('Dont come')
def company_list(request, comp_id = None):
   return ...

If i call company_add views, Iam getting Output as :

This is working
Dont come

But my expected result is

This is working.

Anyone help me to print only the argument belong to the particular views.

  • 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-06-16T11:27:10+00:00Added an answer on June 16, 2026 at 11:27 am

    When you wrap function with @d(arg), you actually run the body of the d function with msg=arg before running decorated function and of course print the msg. You can place the print statement somewhere else, for example:

    def d(msg='my default message'):
        def decorator(func):
            def newfn(request, **kwargs):
                print msg
                return func(request, **kwargs)
            return newfn
        return decorator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using django 1.1 beta release. In my project I want to use
I am using Sphinx with autodoc for documenting my Django project. Design guys want
I'm using the @login_required decorator in my project since day one and it's working
I am using django multiple DB router concepts, having multiple sites with different db's.
I am using Django's built-in comments app. But I have met one problem. The
Iam using jquery tinymce in my django Application. There is a default plugin named
I am using django and I have a file named models.admin.py and I want
I am using django 0.96 for the appengine project. I wanted to use javascript
I am using Django's generic views to create a blog site. The templates I
I am writing forum app on Django using custom session/auth/users/acl system. One of goals

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.