Hello World之Flash Web
作者:雨水,日期:2015年3月23日
说明:Flask是Python的一个比较流行的Web开发框架,最近接触到,这里做一个Hello World。
操作系统环境: Ubuntu 12.04.4 LTS 系统自带Python 2.7.*版本
步骤一: 安装Python虚拟运行环境virtualenv
$ sudo apt-get install python-virtualenv
步骤二:创建虚拟环境venv
$ virtualenv venv
步骤三:启动虚拟环境venv
$cd venv
$source ./bin/activate
(venv)[email protected]:~/venv$
步骤四:安装Flask
(venv)[email protected]:~/venv$ pip install flask
步骤五:编写Hello World程序,内容如下,保存为hello.py
from flask import Flask
app = Flask(__name__)
app = Flask(__name__)
@app.route(“/”)
def hello():
return “Hello World!”
if __name__ == “__main__”:
app.run()
步骤六:运行hello.py
(venv)[email protected]:~/venv$python hello.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
在本机上另外开新窗口,运行:$ curl http://127.0.0.1:5000
Hello World!
步骤七:退出虚拟环境venv
(venv)[email protected]:~/venv$deactivate
参考资料:
1.
https://pypi.python.org/pypi/virtualenv virtualenv is a tool to create isolated Python environments.
https://pypi.python.org/pypi/virtualenv virtualenv is a tool to create isolated Python environments.
2.
http://flask.pocoo.org/ Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.
http://flask.pocoo.org/ Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/12432.html