初学者程序员试图从表格

时间:2018-01-08 18:44:50

标签: python html flask

我是一名初学程序员,正在为我的代码寻求帮助。这是我第一次尝试这个。我现在只进行了一段时间的编程并且遇到了一个骑行块 这是我正在努力工作的按钮:

from flask import Flask
from flask import Flask, flash, redirect, render_template, request, session, abort, url_for
import os

app = Flask(__name__, static_url_path='/static')
        @app.route('/home', methods=['POST', 'GET'])
        def run_home():
        if request.method == 'POST':
            if request.form['bob'] == 'home':
                pass
            return redirect('home', code=302, Response=None)
        elif request.method == 'GET':
            return render_template('home.html', form=form)

这是与上面的烧瓶相关的html。我需要帮助使按钮工作并且卡住了。我正在尝试使用表格来排列链接到不同页面的按钮。任何人都可以帮我弄清楚如何做到这一点吗?

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>Home Page</title>
        <meta charset="UTF-8">
        <meta name="description" content="List of Comics">
        <meta name="author" content="Zach">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <h1 align="center">List of Comics</h1>
        <br />
    </head>
    <header>
        <table cellspacing="10">
            <tr>
                <td><form method ="post" name="bob" action="url_for('home')}}" class="buttons to new page" id="home"><input type="submit" value="Home" name="Home"></form></td>
                <td><form method ="post" name="bob" action="url_for('books')}}" class="buttons to new page" id="books"><input type="submit" value="Books" name="Books"></form></td>
                <td><form method ="post" name="bob" action="url_for('comics')}}" class="buttons to new page" id="issues"><input type="submit" value="Issues" name="Issues"></form></td>
                <td><form method ="post" name="bob" action="url_for('bio')}}" class="buttons to new page" id="bio"><input type="submit" value="Biography" name="Biography"></form></td>
            </tr>
        </table>
    </header>
    <body>
        <a href="books.html"><h2 align="center">Books</h2></a>
        <br />
        <p align="center">These are books containing collections of issues.</p>
        <a href="comics.html"><h2 align="center">Issues</h2></a>
        <br />
        <p align="center" a href="comics.html">These are individual issues.</p>

    </body>
    <footer>
        <table cellspacing="10">
            <tr><form method ="post" name="bob" action="/home" class="buttons to new page">
                <td><input type="submit" value="Home" name="Home" formaction="/home.html" /></td>
                <td><input type="submit" value="Books" name="Books" formaction="/comics.html" /></td>
                <td><input type="submit" value="Issues" name="Issues" formaction="/issues.html" /></td>
                <td><input type="submit" value="Biography" name="Biography" formaction="/bio.html" /></td>
            </form></tr>
        </table>
        <p align="right">Date/Time: <span id="datetime"></span></p>
        <script>
        var dt = new Date();
        document.getElementById("datetime").innerHTML = dt.toLocaleString();
        </script>
    </footer>
</html>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以改为创建form元素,而不是使用<button></button>。如果您希望每个按钮都移到某个位置,可以将它们放在<a>标记中,并在href属性中指定位置。

您的工作不起作用的原因是您正在使用表单的提交按钮。表格应该A)只有一个提交按钮(通常)和B)包括表格数据(如用户名,密码,电子邮件等)。

在表单元素上使用name属性将不起作用。它正在寻找一个值,但form元素没有;一个输入

简而言之:

<a href="/home"><button value="Home"></button></a>
<a href="/books"><button value="Books"></button></a>
<a href="/issues"><button value="Issues"></button></a>
<a href="/biography"><button value="Biography"></button></a>

希望有所帮助!

相关问题