1. Set request method
from Flask Import the Flask App = the Flask ( the __name__ ) # the Flask defined route is achieved by decorator # routed by default only supports GET, if set other, specify their own @ app.route ( " / index " , Methods = [ ' the GET ' , ' the POST ' ]) DEF index (): return " setting mode request " # 4 launcher IF the __name__ == ' __main__ ' : app.run ()
2. Request Processing Parameters
from Flask Import the Flask App = the Flask ( the __name__ ) # <> define the routing parameters, <> need a name within @ app.route ( " / User / <user_id> " ) DEF The get_user (user_id): # required in view of the function fill in the name of the parameter, the default parameter type is a string. Required parameter conversion type int: <int: user_id> return " acquired user S% " % user_id # 4. launcher IF the __name__ == ' __main__ ' : app.run ()
Test Results: