python - 烧瓶不显示电子邮件/密码的值
问题描述
我的 Flask 应用程序遇到了一些问题,而且它似乎没有从我的 SQL 数据库中选择记录。我正在尝试制作一个登录表单,用户在其中输入电子邮件地址和密码 - 然后它从 .db 文件中选择它们都匹配的特定行,然后将这些值作为两个变量返回。没有错误代码,基本功能有效,这意味着没有错误代码。
@app.route("/login", methods=["POST", "GET"])
def login():
if request.method == "GET":
return render_template('login.html')
else:
session.permanent = True
email = request.form["email"]
password = request.form["password"]
with sqlite3.connect("ToDoList.db") as connection:
c = connection.cursor()
c.execute("SELECT * FROM User WHERE email= ? AND password= ? ;", (email, password))
row = c.fetchone()
if row:
session['name'] = row[1]
session['surname'] = row[2]
loggedIn = make_response(render_template("todolist.html", name=session["name"], surname=session["surname"]))
return loggedIn
resp = make_response(render_template('login.html'))
return resp
@app.route("/todolist", methods =['GET', 'POST'])
def todolist():
return render_template("todolist.html")
HTML - 登录
{% extends "base.html" %}
{% block title %} Login Page {% endblock %}
{% block content %}
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for msg in messages %}
<p>{{msg}}</p>
{% endfor %}
{% endif %}
{% endwith %}
<form action="{{ url_for('todolist')}}" method="post">
<p>Email: </p>
<p><input type="email" name="email" /></p>
<p>Password: </p>
<p><input type="password" name="password" /></p>
<p><input type="submit" value ="submit" /></p>
</form>
{% endblock %}
HTML - 待办事项列表
{% extends "base.html" %}
{% block title %} ToDo List {% endblock %}
{% block content %}
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for msg in messages %}
<p>{{msg}}</p>
{% endfor %}
{% endif %}
{% endwith %}
<h1>ToDo App</h1>
<h3>Greetings {{ name }} {{ surname }}</h3>
Below you can enter in tasks for your ToDo list.
<form action="#" method="POST">
<h4>Enter the name of a task for your ToDo list: </h4>
<p><input type="text" name="Task">
<input type="submit" value="Enter"></p>
</form>
{% endblock %}
我真的只想把名字传到这里,这样他们就会出现——
<h3>Greetings {{ name }} {{ surname }}</h3>
解决方案
推荐阅读
- java - SQLite - 从数据库中检索图像并在 ImageView 中显示
- sql - Oracle SQL 当前日期
- python - 将列表中的值匹配到条件为真的索引
- javascript - 页面重新加载后如何在 jQuery ajax .done() 上保留(数据)值
- selenium - Selenium IDE - 将文件上传到字段中
- react-native - ImageBackground 不会出现
- python - 什么框架支持带有基本文本和多边形的简单全屏(即没有可见的镶边)应用程序?
- pyspark - 什么是 LabeledPoint RDD?如何在其中打印数据?
- java - 在为@PathParam 发送带有Url 中数据的反斜杠时,它将作为正斜杠
- javascript - 错误:无法调用 React.createContext,因为对象类型中缺少属性 createContext