21
loading...
This website collects cookies to deliver better user experience
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "I love Flask"
from flask import Flask
app = Flask(__name__)
@app.route("/")
@app.route("/home")
@app.route("/index")
def Index():
return "I love Flask!"
You can use the flask.Flask.route() decorator.
You can use the flask.Flask.add_url_rule() function.
You can directly access the underlying Werkzeug routing system which is exposed as flask.Flask.url_map.
from flask import Flask
app = Flask(__name__)
@app.route("/users", methods=['GET', 'POST', 'PUT'])
def users():
pass
@app.route('/user/<username>')
def user(username):
#... statement(s)
pass
@app.route('/user/<int:id>')
def user(id):
#... statement(s)
pass
If a rule ends with a slash and is requested without a slash by the user, the user is automatically redirected to the same page with a trailing slash attached.
If a rule does not end with a trailing slash and the user requests the page with a trailing slash, a 404 not found is raised.