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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:00:29+00:00 2026-06-13T11:00:29+00:00

I have written two very simple decorators for my django app : def login_required_json(f):

  • 0

I have written two very simple decorators for my django app :

def login_required_json(f):
    def inner(request, *args, **kwargs):
        #this check the session if userid key exist, if not it will redirect to login page
        if not request.user.is_authenticated():
            result=dict()
            result["success"]=False
            result["message"]="The user is not authenticated"
            return HttpResponse(content=simplejson.dumps(result),mimetype="application/json")
        else:
            return f(request, *args, **kwargs)

def catch_404_json(f):
    def inner(*args,**kwargs):
        try:
            return f(*args, **kwargs)
        except Http404:
            result=dict()
            result["success"]=False
            result["message"]="The some of the resources throw 404"
            return HttpResponse(content=simplejson.dumps(result),mimetype="application/json")

But when I apply them to my views I get “ViewDoesNotExist” error in the template, saying it could not import the view because it is not callable. What am i doing wrong?

  • 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-13T11:00:31+00:00Added an answer on June 13, 2026 at 11:00 am
    def login_required_json(f):
        def inner(request, *args, **kwargs):
            #this check the session if userid key exist, if not it will redirect to login page
            if not request.user.is_authenticated():
                result=dict()
                result["success"]=False
                result["message"]="The user is not authenticated"
                return HttpResponse(content=simplejson.dumps(result),mimetype="application/json")
            else:
                return f(request, *args, **kwargs)
    
        return inner   # <--- Here
    

    Your decorator is returning None, instead of the actual view.
    So return the inner function as I’ve demonstrated above.

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

Sidebar

Related Questions

I have written a very simple Chrome extension. It consists of this background page:
I have written an app in C which expects two lines at input. First
I have written a module similar to the following: module One class Two def
I have a very simple problem. I have an application which is written in
I have a problem with a very simple piece of code written in Javascript,
I have written two short tests and compiled both with g++ -S (gcc version
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have written two pieces of code which I intended to have identical outputs,
I have written a Python module, and I have two versions: a pure Python
Hi I have a program written in C++ in which one or two functions

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.