Train Flask

Flask是一個非常好用的web development工具

方便撰寫 RESTful API

方便撰寫 Swagger 2.0 API documentation


Step . install Python


Step . install virtualenv

easy_install virtualenv
pip install virtualenv

Note: virtualenv is a tool to create isolated Python environments.

Step . create a virtual environment for flask

cd ~; mkdir playground; cd playground
virtualenv flask

Step . install flask and extensions
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/bin/pip install flasgger;


"Hello, World" in Flask

Step . Let's start by creating a simple init script for our app package

mkdir app
vim app/
from flask import Flask
from flasgger import Swagger

app = Flask(__name__)

from app import views

Step . Let's write our first view function
vim app/
from app import app

def index():
    return "Hello, World!"

Step . The final step to have a fully working web application is to create a script that starts up the development web server with our application
from app import app'', debug = True)
chmod 755

Step . Now open up your web browser and enter the following URL in the address field
除非特別註明,本頁內容採用以下授權方式: Creative Commons Attribution-ShareAlike 3.0 License