我的 python Flask 应用程序在调用 POST 方法时崩溃

这是我的 app.py 代码:


from flask import Flask

app = Flask(__name__)

from flask import redirect, render_template as rt, url_for, request, flash


import sqlite3

from sqlite3 import Error

con = sqlite3.connect('database.db')



@app.route('/')

def nullPage():

    return redirect('/home/')



@app.route('/home/')

def homePage():

    return rt('homePage.html')



@app.route('/home/signup/', methods=["get", "post"])

def signUp():

    return rt('signUp.html')



@app.route('/home/login/', methods=["get", "post"])

def logIn():

    return rt('logIn.html')



@app.route('/home/logedin/', methods=["get", "post"])

def verLogIn():

    if request.method == 'post':

        passW = request.form['pass']

        email = request.form['email']

        try:

            sql_table(con)

            return "Thanks for loging in!"

        except Error:

            print(Error)

            flash(

                "An error has occured when talking to the database. Please try again later! Thank you for understanding.",

                category='error')



def sql_table(con):


    cursorObj = con.cursor()


    cursorObj.execute(

        "CREATE TABLE credentials(id integer PRIMARY KEY, email text, passWord text)"

    )

    con.commit()

    return print("Commited")



if __name__ == "__main__":

    app.secret_key = 'super secret key'

    # app.config['SESSION_TYPE'] = 'filesystem'

    # sess.init_app(app)

    app.debug = True

    app.run()

    # print("Bye world")```

这是我调用POST方法代码的html代码:


    <!-- @format -->


    {% extends 'base.html' %} {% block head %}

    <div></div>

    <link

        rel="stylesheet"

        href="{{ url_for('static', filename='stylesheets/home.css') }}"

    />

    {% endblock %} {% block body %}

    <header>

        <h1>

            Hi, welcome to the WebEmailApp

        </h1>

    </header>

    {% endblock %}




慕勒3428872
浏览 35回答 1
1回答

RISEBY

你的logedin路线需要返回一些东西。@app.route('/home/logedin/', methods=["get", "post"])def verLogIn():&nbsp; &nbsp; if request.method == 'post':&nbsp; &nbsp; &nbsp; &nbsp; passW = request.form['pass']&nbsp; &nbsp; &nbsp; &nbsp; email = request.form['email']&nbsp; &nbsp; &nbsp; &nbsp; try:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sql_table(con)&nbsp; &nbsp; &nbsp; &nbsp; except Error:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(Error)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flash(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "An error has occured when talking to the database. Please try again later! Thank you for understanding.",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; category='error')&nbsp; &nbsp; return rt('yourtemplate.html')&nbsp; # <---- here
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5