Flask入门教程name='peter')) # 输出:/user/peter print(url_for('test_url_for')) # 输出:/test # 下面这个调用传入了多余的关键字参数,它们会被作为查询字符串附加到 URL 后面。 print(url_for('test_url_for', num=2)) # 输出:/test?num=2 return 'Test page' 数据库工具 (ORM,即对象关系映射)。借助 SQLAlchemy,你可以通过定义 Python 类来表 示数据库里的一张表(类属性表示表中的字段 / 列),通过对这个类进行各种操作 来代替写 SQL 语句。这个类我们称之为模型类,类中的属性我们将称之为字段。 Flask 有大量的第三方扩展,这些扩展可以简化和第三方库的集成工作。我们下面 将使用一个叫做 Flask-SQLAlchemy 的官方扩展来集成 属性调用可选的过滤方法和查询方法,我们就可以获取到 对应的单个或多个记录(记录以模型类实例的形式表示)。查询语句的格式如下: <模型类>.query.<过滤方法(可选)>.<查询方法> 下面是一些常用的过滤方法: 过滤方法 说明 filter() 使用指定的规则过滤记录,返回新产生的查询对象 filter_by() 使用指定规则过滤记录(以关键字表达式的形式),返回新产生 的查询对象 order_by()0 码力 | 127 页 | 7.62 MB | 1 年前3
Flask Documentation (1.1.x)this: /home/user/Projects/flask-tutorial ├── flaskr/ │ ├── __init__.py │ ├── db.py │ ├── schema.sql │ ├── auth.py │ ├── blog.py │ ├── templates/ │ │ ├── base.html │ │ ├── auth/ │ │ └── update.html │ └── static/ │ └── style.css ├── tests/ │ ├── conftest.py │ ├── data.sql │ ├── test_factory.py │ ├── test_db.py │ ├── test_auth.py │ └── test_blog.py ├── venv/ ├── become big, you may want to switch to a different database. The tutorial doesn’t go into detail about SQL. If you are not familiar with it, the SQLite docs describe the language [https://sqlite.org/lang.html]0 码力 | 428 页 | 895.98 KB | 1 年前3
Flask Documentation (1.1.x)__init__.py db.py schema.sql auth.py blog.py templates/ base.html auth/ login.html register.html blog/ create.html index.html update.html static/ style.css tests/ conftest.py data.sql test_factory.py test_db become big, you may want to switch to a different database. The tutorial doesn’t go into detail about SQL. If you are not familiar with it, the SQLite docs describe the language. Connect to the Database user table, and posts in the post table. Create a file with the SQL commands needed to create empty tables: Listing 5: flaskr/schema.sql DROP TABLE IF EXISTS user; DROP TABLE IF EXISTS post; (continues0 码力 | 291 页 | 1.25 MB | 1 年前3
共 3 条
- 1













