Python Jinja2 html按钮:捕捉不同页面上的帖子

Python Jinja2 html按钮:捕捉不同页面上的帖子,python,google-app-engine,jinja2,google-api-python-client,Python,Google App Engine,Jinja2,Google Api Python Client,我有一个GAE应用程序,它使用Jinja2模板为html页面提供服务 现在,在我的主python文件中,我有一个类mainhandler,带有GET和POST方法。这一切都适用于欢迎屏幕,其中有一个按钮可以执行某些操作。单击按钮时,将调用POST方法,该方法将调用第二个页面 我在第二页result.html上找不到关于如何捕获按钮事件的任何信息。并在主python文件中使用progress方法 所以:“如何使用result.html上的errorMail和toCalendar按钮 这是我的主文件

我有一个GAE应用程序,它使用Jinja2模板为html页面提供服务

现在,在我的主python文件中,我有一个类mainhandler,带有GET和POST方法。这一切都适用于欢迎屏幕,其中有一个按钮可以执行某些操作。单击按钮时,将调用POST方法,该方法将调用第二个页面

我在第二页result.html上找不到关于如何捕获按钮事件的任何信息。并在主python文件中使用progress方法

所以:“如何使用result.html上的errorMail和toCalendar按钮

这是我的主文件:

# -*- coding: utf8 -*- 

import webapp2
from apiclient.discovery import build
from oauth2client.appengine import OAuth2Decorator

from format import formatFile

import jinja2
import os

jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))

decorator = OAuth2Decorator(secret)

class MainHandler(webapp2.RequestHandler):
    @decorator.oauth_required
    def get(self):
        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render())

    #processes the file and shows the results
    def post(self):
        # Get the authorized Http object created by the decorator.
        http = decorator.http()

        service = build('calendar', 'v3', http=http,
           developerKey='secret')

        # Make a list of calendars
        calendar_list = service.calendarList().list().execute()

        totalList = formatFile(self.request.get('file'))

        template_values = {"totalList": totalList, "calendar_list": calendar_list}

        template = jinja_environment.get_template('result.html')
        self.response.out.write(template.render(template_values))


app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)
这是page index.html:

<!DOCTYPE html>

<html>
  <head><title></title></head>
  <body>
    <form method="post">
    <div><label>Select file:</label</div>
    <input type="file" name="file">
    <br>
    <input type="submit" name="upload" value="Upload">
    </form>
  </body>
</html>


选择文件:您不必接收按钮事件。您可以像self.request.get('file')一样在post中接收表单数据(包括按钮)

您可以在帖子中添加多个按钮。 通过添加操作,每个表单都可以有自己的post处理程序:

index.html(结果发布到/result1):


result.html(结果发布到/result2):



是否有错误?请发送电子邮件给我。
app=webapp2.WSGIApplication([('/',MainHandler)],debug=True中是否需要添加处理程序?你可以为每一篇文章添加一个处理程序,但你也可以查找路径,找出页面发布/提交了哪些数据。你有没有可能在回答中详细说明一下?选项一:为/result2添加一个单独的处理程序类。你只需处理文章。选项二:路径位于:MainHan的self.request.path中dler:if self.request.path=='result2'..对于第二个选项,处理程序/regex如下所示:app=webapp2.WSGIApplication([('/.',MainHandler),],debug=True),并且app.yaml中的最后一行包含:-url:/.*脚本:main.py
<html>
    <head>

    </head> 
    <body>
        <h3>De volgende data staat klaar voor je agenda:</h3>
        <table border="1" cellpadding="3">
            <tr>
                <th>Dag</th>
                <th>Datum</th>
                <th>Tijd</th>
                <th>Omschrijving</th>
            </tr>
                 {% for line in totalList %}
                <tr>
                    {% for item in line %}
                    <td>{{ item }}</td>
                    {% endfor %}
            </tr>        
            {% endfor %}
        </table>

        <br>
        <b>Selecteer de agende waar de diensten in geplaatst worden:</b>
        <br>
        <select>
            {% for calendar_list_entry in calendar_list['items'] %}
            <option value=>{{ calendar_list_entry['summary'] }}</option>
            {% endfor %}
        </select>
        <br>

        <form method="post">
            <input type="submit" name="toCalendar" value="In kalender plaatsen">
        </form>
        <br>
        <b>Uitvoer incorrect? Klik dan op onderstaande knop om foutmeldings-email te sturen.</b>
        <form method="post">
            <input type="submit" name="errorMail" value="Uitvoer incorrect!">
        </form>

    </body>
</html>
<form action="/result1" method="post">
<form action="/result2" method="post">
    <input id="toCalender " type="submit" name="toCalendar" value="In kalender plaatsen">
    <br>
    <b>Uitvoer incorrect? Klik dan op onderstaande knop om foutmeldings-email te sturen.</b>
    <input id="errorMail" type="submit" name="errorMail" value="Uitvoer incorrect!">
</form>