同一页面上的Python电子邮件验证

同一页面上的Python电子邮件验证,python,html,mysql,validation,flask,Python,Html,Mysql,Validation,Flask,我正在尝试制作一个简单的电子邮件验证应用程序。它只需要页面的索引和成功页面,列出所有的电子邮件。有三个路由:索引路由、验证路由,最后是列出实际电子邮件的成功路由。这是我的密码: from flask import Flask, request, redirect, render_template, session import datetime from mysqlconnection import MySQLConnector app = Flask(__name__) mysql = My

我正在尝试制作一个简单的电子邮件验证应用程序。它只需要页面的索引和成功页面,列出所有的电子邮件。有三个路由:索引路由、验证路由,最后是列出实际电子邮件的成功路由。这是我的密码:

from flask import Flask, request, redirect, render_template, session
import datetime
from mysqlconnection import MySQLConnector

app = Flask(__name__)
mysql = MySQLConnector(app,'friendsdb')

@app.route('/', methods=['POST','GET'])
def index():
    if request.method=='GET':
        return render_template('index.html')
    elif request.method=='POST':
        friends = mysql.query_db("SELECT * FROM friends")
        print friends
        print request.form['first_name'],
        print request.form['last_name'],
        print request.form['Age']
        return render_template('index.html')

#@app.route('/delete/<friend_id>', methods=['POST'])
#def delete(friend_id):
    #query = "DELETE FROM friends WHERE id = :id"
    #data = {'id': friend_id}
    #mysql.query_db(query, data)
    #return redirect('/')

app.run(debug=True)
和我的html:

<!DOCTYPE html>
<head>
  <h1>Friends</h1>
</head>
<body>
  <form action="/" methods="GET">
    <table>
      <th>Name:</th>
      <th>Age:</th>
      <th>Friend Since:</th>
      {% for friends in all_friends: %}
      <tr>ID:{{friends['id']}}</tr>
      <tr>First Name:{{friends['first_name']}}Last Name:{{friends['last_name']}}</tr>
      <tr>Age:{{friends['age']}}</tr>
      <tr>Date:{{friends['NOW();']}}</tr>
      <tr><form action="/delete" method="POST">
        <p>Delete a friend</p> <input type="submit"></tr>
      {%endfor%}
  </form>
    </table>

    <h1>Add a Friend</h1>
  <form action="/" method="POST">
   <p>First Name:</p><input type="text" name="first_name">
   <p>Last Name:</p><input type="text" name="last_name">
   <p>Age</p><input type="text" name="age">
   <input type="submit">
  </form>


  </form>
</body>

我正在尝试将输入的数据输入到顶部的表中。有什么建议吗?

这里有一个最简单的示例,向您演示如何完成此操作,您所做的更改位于render_template行render_templateindex.html上,friends=friends

还有HTML

<!DOCTYPE html>
<head>
  <title>Friends</title>
</head>
<body>

    <table>
        <tr>
            <th>Name:</th>
            <th>Age:</th>
        </tr>

        {% for friend in friends %}
        <tr>
            <td>{{friend['name']}}<td>
            <td>{{friend['age']}}<td>
        </tr>
        {% endfor %}
    </table>

</body>
<!DOCTYPE html>
<head>
  <title>Friends</title>
</head>
<body>

    <table>
        <tr>
            <th>Name:</th>
            <th>Age:</th>
        </tr>

        {% for friend in friends %}
        <tr>
            <td>{{friend['name']}}<td>
            <td>{{friend['age']}}<td>
        </tr>
        {% endfor %}
    </table>

</body>