post()和get()被(重新)定向到同一个模板

时间:2022-11-10 23:15:11
import webapp2
from views import MainPageCourt, CreateCourt, DeleteCourt, EditCourt, Listbox, \
                    MainPage, CreateLocation, DeleteLocation, EditLocation, Unexpected, \
            Schedule

app = webapp2.WSGIApplication([
        ('/', MainPage), 
        ('/unexpected', Unexpected), 
        ('/listbox', Listbox), 
        ('/read/([\w]+)', MainPageCourt), 
        ('/create/([\w]+)', CreateCourt), 
        ('/createlocation/([\w]+)', CreateLocation), 
    ('/schedule/([\w]+)/([\w]+)', Schedule),
        ('/editlocation/([\w]+)', EditLocation),
        ('/deletelocation/([\w]+)', DeleteLocation),
        ('/edit/([\w]+)/([\d]+)', EditCourt),
        ('/delete/([\w]+)/([\d]+)', DeleteCourt)
        ],
        debug=True)





application: scheduler
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /static
  static_dir: static
- url: /create|schedule|createlocation|editlocation|deletelocation|edit|delete/.*
  script: main.app
  login: required

- url: /.*
  script: main.app

libraries:
- name: jinja2
  version: latest
- name: markupsafe                                                              
  version: latest 

builtins:
- remote_api: on

For my primary class class MainPageCourt(BaseHandler): the def post() code is never read and I cannot figure out why. When I press the submit button on the template, nothing happens and there is no reaction in the gae log. I wonder if the problem is that I want both the post() and the get() to "finish" the same way by going to the same page, read.html? Is that a problem or am I looking in the wrong way and wrong place for my problem? If it is the problem, what is an easy workaround?

对于我的主类类MainPageCourt(BaseHandler):def post()代码永远不会被读取,我无法弄清楚原因。当我按下模板上的提交按钮时,没有任何反应,并且gae日志中没有任何反应。我想知道问题是我想让post()和get()以相同的方式“完成”同一个方法,转到同一页面,read.html?这是一个问题,还是我以错误的方式和错误的地方寻找我的问题?如果是问题,什么是简单的解决方法?

The first line below is for the post() and the second is for the get() of MainPageCourt.

下面的第一行是post(),第二行是MainPageCourt的get()。

return webapp2.redirect("/read/%s" % location_id)
self.render_template('read.html', {'courts': courts,'location': location, ... etc ...}

This post relates to this question

这篇文章与这个问题有关

template added below

模板在下面添加

{% extends "base.html" %}
{% block content %}
<p> You can start over at the beginning <a href="/">here.</a> </p>
<p class="schedule" style="width: 850px;"> 
<big>{{ location.moreinfo}} </big> <br /
<form action="" method="post" enctype="multipart/form-data">
       <input type="hidden" name="ID" value="{{ location_id }}"></input>
       <input type="hidden" name="weekday" value="{{ weekday }}"></input>
       <input type="hidden" name="nowweekday" value="{{ nowweekday }}"></input>
       <input type="hidden" name="month" value="{{ month }}"></input>
       <input type="hidden" name="month" value="{{ nowmonth }}"></input>
       <input type="hidden" name="day" value="{{ day }}"></input>
       <input type="hidden" name="year" value="{{ year }}"></input>
       <input type="hidden" name="startTime" value="{{ startTime }}"></input>
       <input type="hidden" name="endTime" value="{{ endTime }}"></input>
{% for name in names %}
       <input type="hidden" name="court" value="{{ name }}"></input>
{% endfor %}
       <h1>{{ weekday }}, {{ month }} {{ day }}, {{ year }} at {{ location_id }} {{ location.venue }}</h1> <br />

       Make a reservation by (1) filling out table fields and then (2) clicking "submit". 
<div id="inputdata">
<input type="submit" value=submit />
</div>

    <table border="1" cellpadding="2" 
      cellspacing="0" class="sortable" id="unique-id" align="center">
      <thead> 
<tr> 
<td>Time</td>
{% for name in names %}
<td>{{ name }}</td>
{% endfor %}
</tr></thead>

    <tbody>
{% for time in times %}
<tr> 
    <td >
    {{ time[2] }}
    </td>
    {% for i in range(names|count) %}
    <td> 
    {{ time[3+i] }}
    </td>
    {% endfor %}
{% endfor %}
</tr> 
    </tbody>
</form>
</table>
  <br />

{% endblock content %}

2 个解决方案

#1


0  

There's no action specified in the form. In the form tag of your template you should add action=Url/Matching/BaseCourt.

表单中没有指定任何操作。在模板的表单标记中,您应添加action = Url / Matching / BaseCourt。

#2


0  

In my template, immediately before the <form action... was an open tag: <br With that fixed, the form is responding.

在我的模板中,紧接在

#1


0  

There's no action specified in the form. In the form tag of your template you should add action=Url/Matching/BaseCourt.

表单中没有指定任何操作。在模板的表单标记中,您应添加action = Url / Matching / BaseCourt。

#2


0  

In my template, immediately before the <form action... was an open tag: <br With that fixed, the form is responding.

在我的模板中,紧接在