我正在尝试创建一个登录表单,通过用户名和密码检查帐户是否存在我已经尝试了一些东西,但似乎无法让它工作
<form id="signupform" action="{{url_for ('login') }}" method="post">
<div class="input-group input-group-lg">
<input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon1" name="username" >
</div>
<div class="input-group input-group-lg">
<input type="password" class="form-control" placeholder="Password (8 chars min)" aria-describedby="sizing-addon1" name="password" " >
</div>
<small id="emailHelp" class="form-text text-muted">
We'll never share your info with anyone else.<br>
<a href="signuppage"> No account? sign up here!</a>
</small>
<button type="button" class="btn btn-primary">Login</button>
</form>
这是表格^^
import os
from flask import Flask, session ,render_template , request
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
app = Flask(__name__)
# Check for environment variable
if not os.getenv("DATABASE_URL"):
raise RuntimeError("DATABASE_URL is not set")
# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return render_template("login.html")
@app.route("/home" , methods=["POST"])
def login():
# request username and password
username=request.form.get("username")
password=request.form.get("password")
#check if account exists
account= db.execute("SELECT * FROM users WHERE username = :username AND password = :password ",
{"username":username , "password":password }).fetchone()
if account is None:
return render_template("loginerror.html")
else:
return render_template("homepage.html")
这是烧瓶应用程序^^
数据库也正确链接所以idk
我很迷茫,真的很感激任何帮助
问题就在这里<button type="button" class="btn btn-primary">Login</button>
。来自MDN 按钮元素文档:
类型
按钮的默认行为。可能的值为:
- submit:按钮将表单数据提交到服务器。如果未为与 a 关联的按钮指定属性,或者该属性为空或无效值,则这是默认值。
- 重置:该按钮将所有控件重置为其初始值,例如 。(这种行为往往会惹恼用户。)
- 按钮:按钮没有默认行为,默认按下时什么也不做。它可以让客户端脚本侦听元素的事件,这些事件在事件发生时被触发。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句