Flask实践——microblog 环境搭建 & helloword (1)

环境搭建 & helloword

  1. 创建项目目录,进入该目录
    mkdir microblog
    cd microblog
  2. 使用virtualen创建独立的运行环境
    virtualenv -p /usr/bin/python3 flask
  3. 进入环境
    source flask/bin/activate
  4. 安装相关模块及扩展
    $ 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
  5. 构建Flask项目框架
    mkdir app
    mkdir app/static
    mkdir app/templates
    mkdir tmp
  6. 创建app/__init__.py
    from flask import Flask
    
    app = Flask(__name__)
    from app import views
  7. 创建app/views.py
    from app import app
    
    @app.route('/')
    @app.route('/index')
    def index():
        return "Hello, World!"
  8. 创建microblog/run.py
    #!flask/bin/python
    from app import app
    app.run(debug = True)
  9. 运行run.py
    http://localhost:5000

     

源码

posted @ 2018-04-26 14:58  lnkDel  阅读(294)  评论(0编辑  收藏  举报