flask-url_for

flask-url_for


  • The flask similar functions and django url_for the reverse function, a view is provided a method of reversing url
  • from flask import Flask, url_for
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        return url_for('test_page', id=6, params=7)  # /page/6?params=7
    
    
    @app.route('/page/<id>')
    def test_page(id):
        return 'index'
    
    
    
    
    
    if __name__ == '__main__':
        app.run()

     

  • The first parameter is a view url_for function returns string __name__
  • If this function has positional parameters, parameter passing keyword arguments directly to the inside of this parameter in url_for
  • When the parameters are not url_for inside the parameters of the function corresponding to the view, the parameter is parsed to get parameter passing (? Pass key reference number)

 

Guess you like

Origin www.cnblogs.com/ivy-blogs/p/11497455.html
URL
URL
URL
URL