如何让 SQLite 在我的 Flask 应用程序中工作?

How to get SQLite working in my Flask application?

我正在 Flask 中构建网络应用程序。我是菜鸟。这是我的第一个应用程序。

我已经按照 SQLite 的安装说明进行操作,现在我的机器上安装了 SQLite。

如何在我的应用程序中包含 SQLite?我需要能够在 app.py

中使用 SQLite

我需要在虚拟环境中包含 SQLite 吗?我该怎么做?

Here is the directory I'm working in

首先你应该像

一样导入SQLlite
import sqlite3 # this library is have from first time in your python so no need to download

之后应该像这样创建数据库:

con = sqlite3.connect('mydatabase.db') # create data base and give name like mydatabase
# but should in last have .db

cur = con.cursor() # for send parameter always you need this

在您可以为您的数据库创建 table 来存储您的项目之后:

cur.execute("CREATE TABLE IF NOT EXISTS session_id (id INTEGER PRIMARY KEY,what yo want MESSAGE_TEXT ,pass_word FLOAT )") 

# with cur.execute first can i created id in my table like every project its good 
# its good to create this for store your items in your database and you create..
# any you want like what you want for ex. create name should MESSAGE_TEXT, and..
# password like INTEGER OR FLOAT OR DOUBLE what you want

con.commit() 

您可以将这样的参数发送到您的 table:

cur.execute("INSERT INTO my_table VALUES name,password))

# in here i just send to parameter because we just create to item in our database
# you can create more, like name, password, session or what you want

con.commit() # and again this because should always have

如果我要说的话,那就太多了,所以我在这里分享了一篇文章的link,以便您可以更好,更深入地学习

Link 更多信息 »» Link

https://www.tutorialspoint.com/sqlite/sqlite_python.htm