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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:10:10+00:00 2026-06-17T07:10:10+00:00

Say I have the following view: def show(request): protect(request) … some more code here…

  • 0

Say I have the following view:

def show(request):
    protect(request)

    ... some more code here...

    return render_to_response
    ...

“protect” is another app view which I am importing like this: from watch.actions import protect

In protect, I make some checks and if a condition is met, I want to use render_to_response right from “protect” and prevent returning to show. If the condition is not met, I want to normally return to “show” and continue the code execution.

How may I do that?

Thanks.

  • 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-17T07:10:11+00:00Added an answer on June 17, 2026 at 7:10 am

    If its only purpose is what you’ve described, you should consider writing protect as a view decorator. This answer provides one example of how to do so.

    Based on view decorators that I have written, your protect decorator could look something like:

    from functools import wraps
    
    from django.utils.decorators import available_attrs
    
    def protect(func):
        @wraps(func, assigned=available_attrs(func))
        def inner(request, *args, **kwargs):
            if some_condition:
                return render_to_response('protected_template')
            return func(request, *args, **kwargs)
        return inner
    

    Which would allow you to then use it like:

    @protect
    def show(request):
       ...
       return render_to_response(...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following code on my view page (in asp.net mvc
Let's say we have following code: struct A{ virtual ~A(){} void f(){ p =
Say I have the following code: <span>Hello world!</span> And the following CSS: span{ color:red;
Say I have the following DOM element in my piece of code: <div id=test>
Say I have the following loop in my view foreach ($value as $row): echo
Let's say I have the following ListView: <ListView ScrollViewer.VerticalScrollBarVisibility=Auto> <ListView.View> <GridView> <GridViewColumn Header=Something DisplayMemberBinding={Binding
Let's say I have the following: <FrameworkElement.Resources> <DataTemplate DataType={x:Type viewmodel:MainViewModel}> <view:MainBaseView /> </DataTemplate> </FrameworkElement.Resources>
Say we have the following two traits: trait Foo[A] { def howMany(xs: List[A]) =
Lets say we have the following: create view view_1 as ( select key, data
lets say i have the following markup: <ul class=editor> <li> <a href=#>Modules</a> <a href=#>View</a>

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.