Python (flask learning)

What is Flask

Flask is using a Python lightweight Web application framework written. Its WSGI toolkit uses Werkzeug, template engine is used Jinja2. Flask use BSD license.
 
 

How to use it

 

That which we write a simple Hello World program to look at.

 

 

 

There are so few files and folders

 

 

 

Where static is to place some of the things about static files, such as css and js files. templates are placed in a variety of template files, etc., MIkasa.py is one of our major operational documentation.

 

Wherein the code file follows Mikasa.py

 

from flask import Flask
app=Flask(__name__)
@app.route("/")
def hello_world():
    return "hello World!"
@app.route("/login")
def to_login():
    return "login_success!"
if __name__=='__main__' :
    app.run()

 

 

Explain, first import the class from the flask in Flask.

 

Then use __name __ (in fact, is __main__, of course, can take another name) to instantiate an object.

 

Using route () function to acquire the route. For example, when calling the function route ( "/") on behalf of the browser to access the home directory hello_world (), the output hello world, access / login, call to_login (), the output login_success

 

Use python3 Mikasa.py executable file. '

 

 

The default settings for the machine Port 5000 open web services.

 

The following is a test page

 

 

 

 

 

 

 

 

 

 

 

 About like this, later expanded to add to it. Because I wanted to learn flask encountered some problems, it has not done very uncomfortable, so wanted to learn from him.

 

Guess you like

Origin www.cnblogs.com/Mikasa-Ackerman/p/11449285.html