概述

每个项目的开始都需要初始化项目,其实python开发项目大同小异,主要是开发思路,今天三哥就来说下flask轻博客系统项目初始化,由于我使用的是archlinux系统,本博客开发环境都是基于linux环境下

项目初始化大致如下:

  • python虚拟环境初始化
  • 基础模板安装
  • 目录结构初始化

python虚拟环境初始化

python虚拟环境初始化相对来说比较简单,详情查看python虚拟环境venv的使用

下面来简单说下初始化步骤:

$ mkdir h3blog      #创建项目目录
$ cd h3blog/        # 进入项目目录
$ python -m venv venv       # 在项目目录下创建python虚拟环境
$ ls        # 创建成功后,目录下会生成 venv文件夹
venv
$ source venv/bin/activate      # 进入python虚拟环境,成功进入后会出现提示符前会出现(venv)
(venv) $ 

到此python虚拟环境初始化成功

基础模板安装

我的技术方向上采用的是flask框架,所以我先把flask框架安装好,以后在遇到新模块的时候,继续安装即可

安装flask模块命令:

pip install flask

安装过程如下:

(venv) $ pip install flask
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting flask
  Downloading https://mirrors.aliyun.com/pypi/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
     |████████████████████████████████| 102kB 4.7MB/s 
Collecting Werkzeug>=0.15 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/ba/a5/d6f8a6e71f15364d35678a4ec8a0186f980b3bd2545f40ad51dd26a87fb1/Werkzeug-1.0.0-py2.py3-none-any.whl (298kB)
     |████████████████████████████████| 307kB 2.5MB/s 
Collecting Jinja2>=2.10.1 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/27/24/4f35961e5c669e96f6559760042a55b9bcfcdb82b9bdb3c8753dbe042e35/Jinja2-2.11.1-py2.py3-none-any.whl (126kB)
     |████████████████████████████████| 133kB 6.5MB/s 
Collecting click>=5.1 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/dd/c0/4d8f43a9b16e289f36478422031b8a63b54b6ac3b1ba605d602f10dd54d6/click-7.1.1-py2.py3-none-any.whl (82kB)
     |████████████████████████████████| 92kB 4.4MB/s 
Collecting itsdangerous>=0.24 (from flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->flask)
  Downloading https://mirrors.aliyun.com/pypi/packages/4b/20/f6d7648c81cb84815d0be935d5c74cd1cc0239e43eadb1a61062d34b6543/MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, click, itsdangerous, flask
Successfully installed Jinja2-2.11.1 MarkupSafe-1.1.1 Werkzeug-1.0.0 click-7.1.1 flask-1.1.1 itsdangerous-1.1.0
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) $ 

目录机构初始化

目录结构如下:

h3blog
├── app
│   ├── admin
│   ├── extensions.py
│   ├── __init__.py
│   ├── main
│   ├── models.py
│   ├── __pycache__
│   ├── settings.py
│   ├── static
│   ├── template_filter.py
│   └── util.py
├── LICENSE
├── logs
│   └── h3blog.log
├── README.md
├── requirements.txt
├── uploads
└── wsgi.py

flask轻博客系统实战开发(1) 一 项目规划