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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:10:39+00:00 2026-05-29T11:10:39+00:00

How to stop execution after self.redirect in request initilization? The method redirect does not

  • 0

How to stop execution after self.redirect in request initilization?

The method redirect does not stop/halt script execution. My initilizer method is called but the process continues into method AnswerHandler.get() but self.user is None because user is not logged.

class BaseRequestHandler(webapp.RequestHandler):
    def __init__(self):
        self.user = None

    def initialize(self, request=None, response=None):
        super(BaseRequestHandler,self).initialize(request, response)

        user = users.get_current_user()

        if not user:
            return self.redirect(users.create_login_url(request.uri))

        self.user = user

class AnswerHandler(BaseRequestHandler):

    def get(self):
        answer = Answer.next_answer_by_user(self.user)
        self.write_template({"answer" : answer})

Tanks!

  • 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-29T11:10:40+00:00Added an answer on May 29, 2026 at 11:10 am

    I would go with this solution:

    class BaseRequestHandler(webapp.RequestHandler):
        def __init__(self):
            self.user = None
    
        def setAuthUser(self):
            user = users.get_current_user()
            if not user:
                self.redirect(users.create_login_url(request.uri))
                return False
            self.user = user
            return True
    
    class AnswerHandler(BaseRequestHandler):
        def get(self):
            if not self.setAuthUser():
                return
            answer = Answer.next_answer_by_user(self.user)
            self.write_template({"answer" : answer})
    

    I understand that you would like to work around having to have 2 lines of code in every handler.

    If you really want that, your other option would be:

    class BaseRequestHandler(webapp.RequestHandler):
        def __init__(self):
            self.user = None
    
        def get(self):
            self.user = users.get_current_user()
            if not self.user:
              self.redirect(users.create_login_url(request.uri))
              return
            self.doGet()
    
        def doGet(self):
            raise Exception("doGet() needs to be implemented by a subclass.")
    
    class AnswerHandler(BaseRequestHandler):
        def doGet(self):
            answer = Answer.next_answer_by_user(self.user)
            self.write_template({"answer" : answer})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing server-side code you need to explicitly stop execution after sending a Location:
Is there a way to immediately stop execution of a SQL script in SQL
In my Application_Start() method, how can I stop the execution of the ASP.NET application
It looks like callback function is executed right after animate is called, not at
I need to stop the execution Is there any procedures for using terminate and
I have a simple Python script that I want to stop executing if a
How do I stop a Java process gracefully in Linux and Windows? When does
How is it possible to resume code execution after an exception is thrown? For
Is there any way to stop the execution of a matlab program from the
I have a node.js script that does some logging to a file using WriteStream.

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.