我试图将sqlite3用于我的python项目。我需要创建一个注册页面来注册用户以访问其他功能。所以我需要检查用户名或电子邮件是否存在。我被禁止使用ORM(抱歉我的英语不好)。我唯一通过的教程是:http://flask.pocoo.org/docs/0.10/tutorial/introduction/ 但我不知道如何使用数据库,如何获取表信息和单元格...... 你能告诉我怎么或给我一个参考? 我想我必须知道这样的命令:
@app.route('/')
def show_entries():
#specially this line
cur = g.db.execute('select title, text from entries order by id desc')
entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]
return render_template('show_entries.html', entries=entries)
答案 0 :(得分:1)
基本上它看起来像这样:
t = ('RHAT',)
c.execute('SELECT * FROM stocks WHERE symbol=?', t)
print c.fetchone()
可以在此处找到更全面的示例:https://docs.python.org/2/library/sqlite3.html