使用flask+sqlite注册账号时报错table user has no column named 'xxx'?,flasksqlite,from flask i
使用flask+sqlite注册账号时报错table user has no column named 'xxx'?,flasksqlite,from flask i
from flask import Flask,render_templatefrom flask import requestimport sqlite3app = Flask(__name__)app.config.update(dict( SECRET_KEY = 'NI CAI CAI KAN' ))@app.route('/',methods=['GET','POST'])def Home(): return "<h5>Welcome to home.Please login</h5>"@app.route('/login',methods=['POST','GET'])def login(): conn = sqlite3.connect('user.db') cu = conn.cursor() try: cu.execute("create table user(users text primary key not null,\ pass text not null)") except sqlite3.OperationalError: pass if request.method == 'POST': u = request.form['username'] p = request.form['password'] cu.execute('select *from user where users=%s' %(u)) data = cu.fetchone() if u==data[0] and p==data[1]: return '</h2>Login!</h2>' elif u!=data[0] or p != data[1]: return '<h2>Username or password error!</h2>' else: return '<h2>Please sign up!</h2>' if request.method == 'GET': return render_template("login.html")@app.route('/register',methods=['GET','POST'])def register(): conn = sqlite3.connect('user.db') cu = conn.cursor() try: cu.execute("create table user(user text primary key not null,\ pass text not null)") except sqlite3.OperationalError: pass if request.method == 'GET': return render_template('register.html') if request.method == 'POST': u = request.form['username'] p = request.form['password'] cu.execute('insert into user(users,pass) values(%s,%s)' %(u,p)) conn.commit() return '<h2>register!</h2>'if __name__ == '__main__': app.run(debug=True)
再注册页面输入abc作为账号密码
提示sqlite3.OperationalError: table user has no column named abc
尝试过将request.form改成request.from.get['username',None]结果报错
method is not subscriptable。。
<form action="/register" method="post">
<p><input name="username"></p> <p><input name="password" type="password"></p> <p><button type="submit">register</button></p> </form>
这是注册页面...
编橙之家文章,
相关内容
- 关于Python3中的stderr日志文件写入?,python3stderr,环境:
- Python3.5报错:获悉当前工作目录中的.py文件?,python3.5.
- g++编译加入-fPIC -shared参数后调用PyRun_SampleString段错误,
- 如何在Python中使用subprocess准备shell执行环境,pythonsub
- Flask 中 url for 不理解是什么意思.甚至不理解其作用,
- flask-sqlalchemy 如何查询关系表中的一个字段?,,class
- 如何在mac上用python批量将word文件转成txt文件,pythontx
- python 字符问题'utf8' codec can't decode byte 0xe6 in position 0,
- peewee postgres ArrayField 和JSONField怎么update数据,peeweepos
- 线上环境部署Django,线上部署django,请问大家是如何在线
评论关闭