Flask Documentation (1.1.x)
Implementing API Exceptions Using URL Processors Deploying with Setuptools Deploying with Fabric Using SQLite 3 with Flask SQLAlchemy in Flask Uploading Files Caching View Decorators Form Validation with WTForms can store information for your own needs, check the documentation of that object (g) and the Using SQLite 3 with Flask for more information. Accessing Request Data For web applications it’s crucial to config.from_mapping( SECRET_KEY='dev', DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), ) if test_config is None: # load the instance config, if it exists, when not testing0 码力 | 428 页 | 895.98 KB | 1 年前3Flask Documentation (1.1.x)
can store information for your own needs, check the documentation of that object (g) and the Using SQLite 3 with Flask for more information. 14 Chapter 1. User’s Guide Flask Documentation (1.1.x), Release rue) app.config.from_mapping( SECRET_KEY='dev', DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), ) (continues on next page) 1.5. Tutorial 23 Flask Documentation (1.1.x), Release 1.1.4 (continued but it should be overridden with a random value when deploying. • DATABASE is the path where the SQLite database file will be saved. It’s under app.instance_path, which is the path that Flask has chosen0 码力 | 291 页 | 1.25 MB | 1 年前3Flask入门教程
数据库。用来操作数据库的数据 库管理系统(DBMS)有很多选择,对于不同类型的程序,不同的使用场景,都会 有不同的选择。在这个教程中,我们选择了属于关系型数据库管理系统 (RDBMS)的 SQLite,它基于文件,不需要单独启动数据库服务器,适合在开发 时使用,或是在数据库操作简单、访问量低的程序中使用。 使用 SQLAlchemy 操作数据库 为了简化数据库操作,我们将使用 SQLAlchemy——一个 config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////' + os.path. join(app.root_path, 'data.db') 注意 这个配置变量的最后一个单词是 URI,而不是 URL。 对于这个变量值,不同的 DBMS 有不同的格式,对于 SQLite 来说,这个值的格式 如下: sqlite:////数据库文件的绝对地址 数据库文件一般放到项目根目录即可, 路径(目前来说,即项目根目录),我们使用它来构建文件路径。数据库文件的名 称和后缀你可以自由定义,一般会使用 .db、.sqlite 和 .sqlite3 作为后缀。 另外,如果你使用 Windows 系统,上面的 URI 前缀部分需要写入三个斜线(即 sqlite:/// )。在本书的示例程序代码里,做了一些兼容性处理,另外还新设 置了一个配置变量,实际的代码如下: 第 5 章:数据库0 码力 | 127 页 | 7.62 MB | 1 年前3
共 3 条
- 1