环境搭建 & helloword
- 创建项目目录,进入该目录
mkdir microblog cd microblog
- 使用virtualen创建独立的运行环境
virtualenv -p /usr/bin/python3 flask
- 进入环境
source flask/bin/activate
- 安装相关模块及扩展
$ flask/bin/pip install flask $ flask/bin/pip install flask-login $ flask/bin/pip install flask-openid $ flask/bin/pip install flask-mail $ flask/bin/pip install flask-sqlalchemy $ flask/bin/pip install sqlalchemy-migrate $ flask/bin/pip install flask-whooshalchemy $ flask/bin/pip install flask-wtf $ flask/bin/pip install flask-babel $ flask/bin/pip install guess_language $ flask/bin/pip install flipflop $ flask/bin/pip install coverage
- 构建Flask项目框架
mkdir app mkdir app/static mkdir app/templates mkdir tmp
- 创建app/__init__.py
from flask import Flask app = Flask(__name__) from app import views
- 创建app/views.py
from app import app @app.route('/') @app.route('/index') def index(): return "Hello, World!"
- 创建microblog/run.py
#!flask/bin/python from app import app app.run(debug = True)
- 运行run.py
http://localhost:5000