昨天我能够毫无问题地运行应用程序,但今天我遇到了这个错误



我使用Python、Flask和MySQL创建了一个应用程序,但现在每次将浏览器指向localhost:8080时都会出现此错误。我不知道该找到什么样的错误,其中一个html页面会包含错误吗?或者它只与应用程序中的代码有关?

"GET/HTTP/1.1";404-

"GET/favicon.ico HTTP/1.1";404-

from flask import Flask, render_template, json, request
from werkzeug.security import generate_password_hash
from werkzeug.security import check_password_hash
import mysql.connector
mydb= mysql.connector.connect(
host= "localhost",
user="aplicatieuser",
password="1234",
database="aplicatie"
)
app = Flask(__name__)
@app.route('/showHome')
def main():
return render_template('index.html')
@app.route('/showSignUp')
def showSignUp():
return render_template('signup.html')

@app.route('/signUp',methods=['POST','GET'])
def signUp():
try:
_name = request.form['inputName']
_email = request.form['inputEmail']
_password = request.form['inputPassword']
if _name and _email and _password:
conn = mysql.connect()
cursor = conn.cursor()
_hashed_password = generate_password_hash(_password)
cursor.callproc('sp_createUser',(_name,_email,_hashed_password))
data = cursor.fetchall()
if len(data) == 0:
conn.commit()
return json.dumps({'message':'User created successfully !'})
else:
return json.dumps({'error':str(data[0])})
else:
return json.dumps({'html':'<span>Enter the required fields</span>'})
except Exception as e:
return json.dumps({'error':str(e)})
finally:
cursor.close() 
conn.close()
@app.route('/showSignin')
def showSignin():
return render_template('signin.html')
@app.route('/showTodo')
def showTodo():
return render_template('todo.html')
if __name__ == "__main__":
app.run(port=8080)

您没有为根定义路由"&";。所以改变:

@app.route('/showHome')
def main():
return render_template('index.html')

收件人:

@app.route('/')
def main():
return render_template('index.html')

或者使用:http://localhost:8080/showHome在您的浏览器中。

相关内容

最新更新