Flask-数据库

1.安装模块操作

D:\MySpace\FlaskDemo>venv\scripts\activate 激活虚拟环境
(venv) D:\MySpace\FlaskDemo>
(venv) D:\MySpace\FlaskDemo>pip list

Package    Version
---------- -------
pip        10.0.1
setuptools 40.0.0
wheel      0.31.1

(venv) D:\MySpace\FlaskDemo>pip install Flask-OpenID
(venv) D:\MySpace\FlaskDemo>pip freeze > requirements.txt
(venv) D:\MySpace\FlaskDemo>pip install flask_sqlalchemy 数据库相关模块

2.数据库学习

教程参看quickstart官方文档


(venv) D:\MySpace\FlaskDemo>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
 on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from app import db,models

D:\MySpace\FlaskDemo\venv\lib\site-packages\flask_sqlalchemy\__init__.py:794: FS
ADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead an
d will be disabled by default in the future.  Set it to True or False to suppres
s this warning.
  'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '

>>> db.create_all()  (此时会多出来个app.db文件)
>>> admin =models.User(username='admin', email='[email protected]')
>>> guest =models.User(username='guest', email='[email protected]')
>>> db.session.add(admin)
>>> db.session.add(guest)
>>> db.session.commit()
>>> models.User.query.all()

[, ]
>>>

你可能感兴趣的:(Flask-数据库)