Flask Documentation (1.1.x)org/about.html] database to store users and posts. Python comes with built-in support for SQLite in the sqlite3 [https://docs.python.org/3/library/sqlite3.html#module-sqlite3] module. SQLite is convenient because some point when handling a request, and closed before the response is sent. flaskr/db.py import sqlite3 import click from flask import current_app, g from flask.cli import with_appcontext def get_db(): time it’s called. After the context, the connection should be closed. tests/test_db.py import sqlite3 import pytest from flaskr.db import get_db def test_get_close_db(app): with app.app_context():0 码力 | 428 页 | 895.98 KB | 1 年前3
Flask Documentation (1.1.x)a SQLite database to store users and posts. Python comes with built-in support for SQLite in the sqlite3 module. SQLite is convenient because it doesn’t require setting up a separate database server and when handling a request, and closed before the response is sent. Listing 4: flaskr/db.py import sqlite3 import click from flask import current_app, g from flask.cli import with_appcontext def get_db(): 5. Tutorial 45 Flask Documentation (1.1.x), Release 1.1.4 Listing 35: tests/test_db.py import sqlite3 import pytest from flaskr.db import get_db def test_get_close_db(app): with app.app_context():0 码力 | 291 页 | 1.25 MB | 1 年前3
Flask入门教程app.root_path 返回程序实例所在模块的 路径(目前来说,即项目根目录),我们使用它来构建文件路径。数据库文件的名 称和后缀你可以自由定义,一般会使用 .db、.sqlite 和 .sqlite3 作为后缀。 另外,如果你使用 Windows 系统,上面的 URI 前缀部分需要写入三个斜线(即 sqlite:/// )。在本书的示例程序代码里,做了一些兼容性处理,另外还新设 置了一个配置变量,实际的代码如下:0 码力 | 127 页 | 7.62 MB | 1 年前3
共 3 条
- 1













