Flask学习笔记分享

本文详细介绍了如何使用Git下载项目,创建并激活Python虚拟环境,通过Pip安装Flask及依赖包,包括Alembic、Blinker、Click等,并展示了如何运行Flask应用和配置数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载:

git clone https://github.com/greyli/helloflask.git

2.安装虚拟环境

python -m venv env

3.激活

source env/bin/activate

4.安装依赖

pip install -r requirements.txt


Collecting alembic==1.0.0 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/96/c7/a4129db460c3e0ea8fea0c9eb5de6680d38ea6b6dcffcb88898ae42e170a/alembic-1.0.0-py2.py3-none-any.whl (158kB)
    100% |████████████████████████████████| 163kB 12kB/s
Collecting blinker==1.4 (from -r requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/1b/51/e2a9f3b757eb802f61dc1f2b09c8c99f6eb01cf06416c0671253536517b6/blinker-1.4.tar.gz
Collecting click==6.7 (from -r requirements.txt (line 3))
  Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl
Collecting cssmin==0.2.0 (from -r requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/8e/d8/dc9da69bb186303f7ab41adef0a5b6d34da2fdba006827620877760241c3/cssmin-0.2.0.tar.gz
Collecting flask-assets==0.12 (from -r requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/86/ff/6000451570745d7a90847f6528d96d6b24c800eaaf9f26cf398accd8cee5/Flask-Assets-0.12.tar.gz
Collecting flask-caching==1.4.0 (from -r requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/63/c0/5dce9fe8372a7b57b60ec7650e1aeb1a2f861393b0c6e7e2dcb71d2f31ab/Flask_Caching-1.4.0-py2.py3-none-any.whl
Collecting flask-ckeditor==0.4.3 (from -r requirements.txt (line 7))
  Downloading https://files.pythonhosted.org/packages/fa/b6/166a3e196351fa9fd291d511586015832da1eeec93ab2aad6fb4be3894a9/Flask_CKEditor-0.4.3-py2.py3-none-any.whl (4.9MB)
    100% |████████████████████████████████| 4.9MB 15kB/s
Collecting flask-debugtoolbar==0.10.1 (from -r requirements.txt (line 8))
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/flask-debugtoolbar/
  Downloading https://files.pythonhosted.org/packages/c9/3c/309073df635148f3536a5ed67940fb9b51ca67c1d6d2debafb81533201f3/Flask_DebugToolbar-0.10.1-py2.py3-none-any.whl (326kB)
    100% |████████████████████████████████| 327kB 27kB/s
Collecting flask-dropzone==1.4.6 (from -r requirements.txt (line 9))
  Downloading https://files.pythonhosted.org/packages/78/f4/12849e5562681d82c40cac14d4a8e1ba5b18e70ab28f112e4d3f0d2cc514/Flask_Dropzone-1.4.6-py2.py3-none-any.whl
Collecting flask-mail==0.9.1 (from -r requirements.txt (line 10))
  Using cached https://files.pythonhosted.org/packages/05/2f/6a545452040c2556559779db87148d2a85e78a26f90326647b51dc5e81e9/Flask-Mail-0.9.1.tar.gz
Collecting flask-migrate==2.2.1 (from -r requirements.txt (line 11))
  Downloading https://files.pythonhosted.org/packages/59/97/f681c9e43d2e2ace4881fa588d847cc25f47cc98f7400e237805d20d6f79/Flask_Migrate-2.2.1-py2.py3-none-any.whl
Collecting flask-sqlalchemy==2.3.2 (from -r requirements.txt (line 12))
  Using cached https://files.pythonhosted.org/packages/a1/44/294fb7f6bf49cc7224417cd0637018db9fee0729b4fe166e43e2bbb1f1c8/Flask_SQLAlchemy-2.3.2-py2.py3-none-any.whl
Collecting flask-wtf==0.14.2 (from -r requirements.txt (line 13))
  Using cached https://files.pythonhosted.org/packages/60/3a/58c629472d10539ae5167dc7c1fecfa95dd7d0b7864623931e3776438a24/Flask_WTF-0.14.2-py2.py3-none-any.whl
Collecting flask==1.0.2 (from -r requirements.txt (line 14))
  Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
Collecting itsdangerous==0.24 (from -r requirements.txt (line 15))
  Using cached https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz
Collecting jinja2==2.10 (from -r requirements.txt (line 16))
  Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting jsmin==2.2.2 (from -r requirements.txt (line 17))
  Downloading https://files.pythonhosted.org/packages/17/73/615d1267a82ed26cd7c124108c3c61169d8e40c36d393883eaee3a561852/jsmin-2.2.2.tar.gz
Collecting mako==1.0.7 (from -r requirements.txt (line 18))
  Using cached https://files.pythonhosted.org/packages/eb/f3/67579bb486517c0d49547f9697e36582cd19dafb5df9e687ed8e22de57fa/Mako-1.0.7.tar.gz
Collecting markupsafe==1.0 (from -r requirements.txt (line 19))
  Using cached https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz
Collecting python-dateutil==2.7.3 (from -r requirements.txt (line 20))
  Using cached https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl
Collecting python-dotenv==0.10.0 (from -r requirements.txt (line 21))
  Using cached https://files.pythonhosted.org/packages/5d/0a/07199c77b5054f5f3b6c3b167fd794ca3fd071f9640ce1af16497516f2df/python_dotenv-0.10.0-py2.py3-none-any.whl
Collecting python-editor==1.0.3 (from -r requirements.txt (line 22))
  Using cached https://files.pythonhosted.org/packages/65/1e/adf6e000ea5dc909aa420352d6ba37f16434c8a3c2fa030445411a1ed545/python-editor-1.0.3.tar.gz
Collecting python-http-client==3.1.0 (from -r requirements.txt (line 23))
  Downloading https://files.pythonhosted.org/packages/5c/5c/9e0cde562757bdb385a3644235e7c4da6f76c8a43d573eb76384ef461d40/python_http_client-3.1.0-py3-none-any.whl
Collecting redis==2.10.6 (from -r requirements.txt (line 24))
  Downloading https://files.pythonhosted.org/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl (64kB)
    100% |████████████████████████████████| 71kB 13kB/s
Collecting sendgrid==5.3.0 (from -r requirements.txt (line 25))
  Downloading https://files.pythonhosted.org/packages/e0/84/44f7c29a111c5595304f173717800f15dc7ee137214eb42686dc2059f06a/sendgrid-5.3.0-py2.py3-none-any.whl
Collecting six==1.11.0 (from -r requirements.txt (line 26))
  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting sqlalchemy==1.2.10 (from -r requirements.txt (line 27))
  Using cached https://files.pythonhosted.org/packages/8a/c2/29491103fd971f3988e90ee3a77bb58bad2ae2acd6e8ea30a6d1432c33a3/SQLAlchemy-1.2.10.tar.gz
Collecting webassets==0.12.1 (from -r requirements.txt (line 28))
  Downloading https://files.pythonhosted.org/packages/9a/35/d86c6d3bd31e2e9c8351c8766ef3688c75d56bc5233ed49061e522efc3cc/webassets-0.12.1.tar.gz (179kB)
    100% |████████████████████████████████| 184kB 8.4kB/s
Collecting werkzeug==0.14.1 (from -r requirements.txt (line 29))
  Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Collecting wtforms==2.2.1 (from -r requirements.txt (line 30))
  Using cached https://files.pythonhosted.org/packages/9f/c8/dac5dce9908df1d9d48ec0e26e2a250839fa36ea2c602cc4f85ccfeb5c65/WTForms-2.2.1-py2.py3-none-any.whl
Collecting argh==0.26.2 (from -r requirements.txt (line 32))
  Using cached https://files.pythonhosted.org/packages/06/1c/e667a7126f0b84aaa1c56844337bf0ac12445d1beb9c8a6199a7314944bf/argh-0.26.2-py2.py3-none-any.whl
Collecting pathtools==0.1.2 (from -r requirements.txt (line 33))
  Using cached https://files.pythonhosted.org/packages/e7/7f/470d6fcdf23f9f3518f6b0b76be9df16dcc8630ad409947f8be2eb0ed13a/pathtools-0.1.2.tar.gz
Collecting pyyaml==3.13 (from -r requirements.txt (line 34))
  Using cached https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz
Collecting watchdog==0.8.3 (from -r requirements.txt (line 35))
  Using cached https://files.pythonhosted.org/packages/54/7d/c7c0ad1e32b9f132075967fc353a244eb2b375a3d2f5b0ce612fd96e107e/watchdog-0.8.3.tar.gz
Installing collected packages: six, python-dateutil, python-editor, sqlalchemy, markupsafe, mako, alembic, blinker, click, cssmin, werkzeug, itsdangerous, jinja2, flask, webassets, flask-assets, flask-caching, flask-ckeditor, flask-debugtoolbar, flask-dropzone, flask-mail, flask-sqlalchemy, flask-migrate, wtforms, flask-wtf, jsmin, python-dotenv, python-http-client, redis, sendgrid, argh, pathtools, pyyaml, watchdog
  Running setup.py install for python-editor ... done
  Running setup.py install for sqlalchemy ... done
  Running setup.py install for markupsafe ... done
  Running setup.py install for mako ... done
  Running setup.py install for blinker ... done
  Running setup.py install for cssmin ... done
  Running setup.py install for itsdangerous ... done
  Running setup.py install for webassets ... done
  Running setup.py install for flask-assets ... done
  Running setup.py install for flask-mail ... done
  Running setup.py install for jsmin ... done
  Running setup.py install for pathtools ... done
  Running setup.py install for pyyaml ... done
  Running setup.py install for watchdog ... done
Successfully installed alembic-1.0.0 argh-0.26.2 blinker-1.4 click-6.7 cssmin-0.2.0 flask-1.0.2 flask-assets-0.12 flask-caching-1.4.0 flask-ckeditor-0.4.3 flask-debugtoolbar-0.10.1 flask-dropzone-1.4.6 flask-mail-0.9.1 flask-migrate-2.2.1 flask-sqlalchemy-2.3.2 flask-wtf-0.14.2 itsdangerous-0.24 jinja2-2.10 jsmin-2.2.2 mako-1.0.7 markupsafe-1.0 pathtools-0.1.2 python-dateutil-2.7.3 python-dotenv-0.10.0 python-editor-1.0.3 python-http-client-3.1.0 pyyaml-3.13 redis-2.10.6 sendgrid-5.3.0 six-1.11.0 sqlalchemy-1.2.10 watchdog-0.8.3 webassets-0.12.1 werkzeug-0.14.1 wtforms-2.2.1
You are using pip version 18.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(env) apple@appledeMacBook-Pro-3 helloflask % pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 18.1

5.执行成功

pipenv install --dev
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile.lock (23243a)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 34/34 — 00:00:09

 

6.执行命令

cd demo/hello

flack run

form的例子:

flask run
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 294-317-457

7.database

flask run
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with fsevents reloader
 * Debugger is active!
 * Debugger PIN: 294-317-457
 

8.cathe

9.Template

10 email

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KENYCHEN奉孝

您的鼓励是我的进步源泉

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值