1. endpoint
from Flask Import Flask, the url_for # instantiate an object is Flask App = Flask ( the __name__ ) # print default configuration information # redistribute development environment app.config.from_object ( ' settings.DEV ' ) # introduced into the production environment configuration # App. config.from_object ( 'settings.Pro') @ app.route ( ' / index ' , Methods = [ ' the GET ' , ' the POST ' ], endpoint = ' XX ' ) DEF index (): "" " If no endpoint ,The default is the name of the function Can be reversed by url_for generation request URL "" " Print (url_for ( ' XX ' )) return ' Ni de mA, ZA Hui Shi! ' IF the __name__ == ' __main__ ' : app.run ()
Print Results:
2. Dynamic Routing
app.route @ ( ' / index / <int: ID> ' , Methods = [ ' the GET ' , ' the POST ' ]) DEF index (ID): "" " If no endpoint, the function name is a default by url_for can reverse generation request URL "" " Print (ID) return ' Ni de mA, ZA Hui Shi! '
Description: <int: id> here <> java equivalent dynamic routing {}, int parameter indicating the type of string type indicates not write
app.route @ ( ' / index / <int: ID> ' , Methods = [ ' the GET ' , ' the POST ' ]) DEF index (ID): "" " If no endpoint, the function name is a default by url_for can reverse generation request url "" " Print (url_for ( ' index ' , the above mentioned id = 1)) # reverse route generation, which is a little sad the Print (the above mentioned id) return ' Ni de mA, ZA Hui shi! '