Local Development Environment: My computer can be server and client at the same time
# flask basic code
# app.py: server file
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'This is Garden server!'
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
When there is html file in templates directory, we can use render it in app.py with importing render_template.
API: a window server made to get client's request
@app.route('/test', methods=['GET'])
def test_get():
title_receive = request.args.get('title_give')
print(title_receive)
return jsonify({'result': 'success', 'msg': '이 요청은 GET!'})
SERVER: in 127.0.0.1/5000/test page, if you "GET" something('title_give'), the variable title_receive will be the result. Send back my response {'result': 'success', 'msg': '이 요청은 GET!'} to client.
$.ajax({
type: "GET",
url: "/test?title_give=봄날은간다",
data: {},
success: function(response){
console.log(response)
}
})
CLIENT: I'm gonna request "title_give=봄날은간다" to server. If i get success for some data, print response to console.