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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:22:05+00:00 2026-06-15T11:22:05+00:00

In my views I am using some module which connects to external api. I

  • 0

In my views I am using some module which connects to external api.
I want this module to throw some custom exception like for example ApiServerNotRespond.
Then I want this exception to cause custom view/template to be rendered. For example if in my view “connect_to_api” (where I am using my api module) api module will cause ApiServerNotRespond exception then for example not_respond view is called instead or just myapp/not_respomd.html template rendered.

I don’t want to use any middleware things because I want all config reside in my app dir not in settings file.

Where and how I can define custom exception and how to force it to render custom template after it is raised?

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

    I think you can achieve this by writing a decorator.

    The decorator should catch ApiServerNotRespond or any other exception you want. And if such exception occurs return response with template you want otherwise just return response from the original view.

    Sample:

    def custom_error_handler():
        def decorator(orig_func):
            def inner_func(request, *args, **kwargs):
                try:
                    return orig_func(request, *args, **kwargs)
                except ApiServerNotRespond:
                    context = {}
                    return render_to_response('custom_template.html', context
                             context_instance = RequestContext(request))
                except Exception:
                    #handle all other errors, may be just raise
                    raise 
           return wraps(orig_func)(inner_func)
        return decorator 
    

    In your views.py,

    @custom_error_handler
    def sample_view1(request):
        #your code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with overlaying views using the prism framework.Its a little more
I have some view which lists my module table entries. What is the most
I've built a view using the views module in Drupal to display a grid
I have a Rails application with several models-views-controllers which have some similar characteristics, for
I’ve been using Views to selectively returned nodes, but right now I want to
I'm making an app, which requires users to upload some files. I want to
I'm using some javascript/jquery in an asp.net mvc view and I'm appending some html
How to render partial view in some specific div without using ajax in asp.net
I have a View where some input text to be added dynamica using jquery,
I'm using the getX() and getY() method on a view for some special dragging

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.