flask 라우팅을 사용하는 방법
from flask import jsonify, redirect, url_for
@app.route('/test/name/<name>')
def name(name):
return f"name is {name},{escape(type(name))}"
@app.route('/test/id/<int:id>')
def id(id):
return 'Id: %d' % id
@app.route('/test/path/<path:subpath>')
def path(subpath):
return subpath
@app.route('/test/json')
def json():
return jsonify({'hello':'world'})
@app.route('/test/redirect/<path:subpath>')
def redirect_url(subpath):
return redirect(subpath)
@app.route('/test/urlfor/<path:subpath>')
def urlfor(subpath):
return redirect(url_for('path',subpath=subpath))
flask mehod 사용하는 방법
from flask import request
@app.route('/test/method/<id>', methods=['GET','POST'])
def method(id):
return jsonify({
'request.args':request.args,
'request.form':request.form,
'request.json':request.json,
'request.method':request.method
})