Routing flask (5)

 About flask routing section, the following knowledge:

app.url_map View all routes

 

Multiple views of the same routing decorative function

 

Routing a plurality of the same view decorator

 

The use of methods to restrict access mode

@app.route('/sample', methods=['GET', 'POST'])

 

Use url_for anti resolved

 

Dynamic Routing

# Parameters as default route passed string processing, here designated int, the contents of the colon is dynamic angle brackets 
@ app.route ( ' / User / <int: ID> ' )
 DEF hello_itcast (ID):
     return  ' Hello itcast D% ' % ID

 

 

Custom converter

 

from flask import Flask
from werkzeug.routing import BaseConverter

class Regex_url(BaseConverter):
    def __init__(self,url_map,*args):
        super(Regex_url,self).__init__(url_map)
        self.regex = args[0]

app = Flask(__name__)
app.url_map.converters['re'] = Regex_url

@app.route('/user/<re("[a-z]{3}"):id>')
def hello_itcast(id):
    return 'hello %s' %id

 

Guess you like

Origin www.cnblogs.com/lirunsheng/p/10996063.html