Using a lot of frameworks and languages, and finally found that Python and flask are more flexible. After so many years of web development, I finally found the true love. Needless to say, write this to record their own some of the experience, first in accordance with the Mega God tutorial to turn. Some of your own experience will be added later.
The installation of flask is recommended to use VIRTUALENV first to build a harmonious environment of non-interference. There is no use here Oh, lazy!!! Installed under Ubuntu is as follows:
$sudo apt-get install python-virtualenv
Windows will not say it. Then install the Flask
$ apt-get install flask
"Hello, World" First we create an app folder for storing items. and the new static folder is stored as some static files (js,css,images, etc.). :) and templates as a template file.
$ mkdir app$ mkdir app/static$ mkdir app/templates$ mkdir tmp
Then first we create a new initialization file (app/__init__.py) for the module, and the contents are as follows:
fromFlaskImport Flaskapp= Flask(__name__) #创建Flask Application Object fromappImportViews #引入视图, not yet realized
We then create a app/views.py file with the following contents:
fromappImportapp@app.Route('/')@app.Route('/index ')defIndex(): return "Hello, world!."
The above even a decorator, is the map of the URL, where, respectively, is the mapping/also/index the last new folder called run.py content as follows
#!flask/bin/python fromappImportAppapp.debug = Trueapp.run (host= ' 0.0.0.0 ') #这样用来监听所有的ip, team commissioning
Then, at the command line, you'll see a hint like the following, * Running on http://0.0.0.0:5000/. run.py
* Restarting with Reloader
Then test it in the browser. Verygood.
Flask Easy Start Tutorial One, small table hit HelloWorld, run up yo