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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:04:17+00:00 2026-06-11T19:04:17+00:00

This question started as the question at this link I think the problem is

  • 0

This question started as the question at this link

I think the problem is in the template unexpected.html (further below). The python code works fine, but when the user supplies a number and then clicks the submit button, the python code accepts the value and no matter which branch of the if clauses are taken, the resulting view in the browser is both the unexpected.html and the embedded html at the bottom of the python code.

Why doesn’t the browser stop with just the unexpected.html template?

First below is the python code.

class MainPage(BaseHandler):

    def get(self):
    self.render_template('index.html', { })

    def post(self):
    number = self.request.get('number')
    hiddennumber = self.request.get('hiddennumber')
    for i in ["a"]:
        if int(number) < int(hiddennumber):
        reason='< was in that time slot already: '
        trans = Trans(key_name='reason')
        trans.reason=reason
        trans.name=number
        trans.put()
        template_values = {'trans':trans}
        path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
        self.response.out.write(template.render(path, template_values))
        elif int(number) > int(hiddennumber):
        reason='> was in that time slot already: '
        trans = Trans(key_name='reason')
        trans.reason=reason
        trans.name=number
        trans.put()
        template_values = {'trans':trans}
        path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
        self.response.out.write(template.render(path, template_values))
        else:
        pass
    self.response.out.write('''
        <html>
          <body>
            <form method="post">
              <p>Name: <input type="text" name="name" /></p>
              <p>Favorite foods:</p>
              <select name="favorite_foods" multiple size="4">
                <option value="apples">Apples</option>
                <option value="bananas">Bananas</option>
                <option value="carrots">Carrots</option>
                <option value="durians">Durians</option>
              </select>
              <p>Birth year: <input type="text" name="birth_year" /></p>
              <p><input type="submit" /></p>
            </form>
          </body>
        </html>
        ''')

class Unexpected(BaseHandler):

    def get(self):
        trans=Trans.get_by_key_name('reason')
        template_values = {'trans':trans}
        path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
        self.response.out.write(template.render(path, template_values))

    def post(self):
        day=self.request.get('day')
        return webapp2.redirect("/")

app = webapp2.WSGIApplication([
        ('/', MainPage), 
        ('/unexpected', Unexpected)
        ],
        debug=True)

The template unexpected.html is next.

{% extends "base.html" %}
{% block content %}


<form action="" method="post" >
<input type="hidden" name="day" value="{{ day }}"/>
This unexpected result occurred: <emph style="font-weight: bold">{{ trans.reason }}</emph>
<br /><br />
<div id="inputdata">
<label>Click the "Ok" button to go back to the previous page so you can edit your entry.
</label>
<input type="submit" value="submit" />
</div>
</form>
<button onclick="window.history.back()">Ok</button>

{% endblock content %}

Finally, I am including index.html for greater completeness.

{% extends "base.html" %}
{% block content %}
<center>
   </h1>
  </center>
<form action="" method="post">
<input type="hidden" name="hiddennumber"  value="10">
<label>Location/Venue name (no spaces and case counts)</label>
<input type="textbox" name="number" size="30" value=""></input><br/>
  <input type="submit" value=submit />
</form>


{% endblock content %}
  • 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-11T19:04:18+00:00Added an answer on June 11, 2026 at 7:04 pm

    Nowhere do you break out of the flow of execution that I can see, and the embedded HTML would be after the tests so there’s no reason it wouldn’t execute. The fastest solution would just be to return when you’re done:

    self.response.out.write(template.render(path, template_values))
    return
    ...
    

    In general you also have a lot of duplicated logic in that structure also: that should be consolidated and then the code could be further refactored to be more readable by making that structure more of just a dispatcher with the appropriate display logic in separate functions.

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

Sidebar

Related Questions

This question is also started from following link: shared memory optimization confusion In above
I originally started this question in another thread, but that thread was sorta, kinda
I've started this question Named route with nested resources , and it lead me
This question most closely relates to the asp.net mvc3 framework. It started out as
Started with this question: OpenID. How do you logout OK. So OpenID does not
I know this question has kind-a started religious wars in past and there might
Forgive if this question is silly. I just started reading the SugarCRM developer documentation
Let me preface this question. I have just started using jquery, so please be
I've just started learning ruby, so this question is simple. I created @subject in
I've started to become a Good Citizen, as per this question here: Domain compatibility:

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.