Flask Easy Start Tutorial One, small table hit HelloWorld, run up yo

Source: Internet
Author: User
Tags virtualenv

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.