1. request.args.get('name') 으로 구하기

 

python flask 코드

# app.py

from flask import Flask, request

app = Flask(__name__)

@app.route('/get')
def get():
    arg = request.args.get('data')
    arg2 = request.args.get('data2')
    print(arg,arg2)
    return arg + arg2

app.run(host='0.0.0.0', debug=True, port="1234")

http://localhost:1234/get?data=Hello&data2=World 

 

 

2. URL 에 변수 추가하기

 

# app.py

from flask import Flask, request

app = Flask(__name__)

@app.route('/get/<arg>/<arg2>')
def get(arg,arg2):
    print(arg,arg2)
    return arg + arg2

app.run(host='0.0.0.0', debug=True, port="1234")

 

http://localhost:1234/get/Hello/World

 

편한 방법으로 사용하자.

 

Reference : https://flask.palletsprojects.com/en/1.1.x/quickstart/

+ Recent posts