
쿠키는 텍스트 파일 형태로 클라이언트 PC 에 저장된다. 더 나은 방문자 경험과 사이트 통계를 위해 클라이언트 사용과 관련된 데이터를 저장하는 것이다. 파일명 : 9_cookies.py from flask import Flask, render_template, request, make_response app = Flask(__name__) @app.route('/') def index(): return render_template('9_index.html') @app.route('/setcookie', methods = ['POST', 'GET']) def setcookie(): if request.method == 'POST': user = request.form['nm'] resp = make_res..

Flask는 몇 줄의 코드만으로 간단하게 HTML FORM 데이터 송수신을 할 수 있다. 파일명 : 8_sending_form_data.py # form 데이터를 송수신하기 위해서는 request 를 import 해야한다. from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def student(): # ROOT URL 로 접근했을 때 8_sending_form_data.html 을 렌더링한다. return render_template('8_sending_form_data.html') @app.route('/result',methods = ['POST', 'GET']) def result(): # r..

Jinja2 에서는 render_template() 함수를 이용하여 html 파일을 렌더링 할 수 있다. 패키지 경로 또는 모듈이 위치한 경로에 templates 디렉토리를 만들고 그곳에 html 파일을 생성하기만 하면 된다. 정적 파일 (Static file) 도 이와 유사한 방식으로 사용할 수 있다. 패키지 경로 또는 모듈이 위치한 경로에 static 디렉토리를 만들고, 그곳에 css 나 자바스크립트와 같은 static file 을 위치시키면 된다. 파일명 : 7_static_files.py from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): # 7_static_files.html 을 렌더..

route() 데코레이터에 의해 실행되는 함수의 리턴값으로 문자열을 셋팅하면 웹 브라우저 상에 해당하는 문자열이 출력된다는 것을 알 수 있다. 2019/03/21 - [Flask] - [Flask] Application (Hello World) 그런데 단순한 문자열이 아닌 HTML 형식을 리턴할 수도 있다. 아래 프로그램을 실행해보자. 파일명 : 6_templates_test.py from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello World' if __name__ == '__main__': app.run(debug=True) 태그가 적용된 Hello World 문자열이 브라우저에 보여진다. 하지만..