Python Bottle Web Framework Intelligent software Lab Bottle

Python Bottle Web Framework Intelligent software Lab. 전재원









Bottle 작성 해 보기 • Bottle의 구성요소 • Routing : @route(‘/hello/<name>’) • Server : run(host=‘localhost’, port=8080) • Template : ‘/hello/<name>’ ‘<b>Hello {{name}}</b>!’ 10





Bottle HTTP request methods • HTTP protocol 처리 15

Bottle HTTP request methods 16


Bottle Static Files 18

Bottle Error Page, Redirection • 404 Error, 찾는 페이지가 서버에 없는 경우 • Error Page 띄우기 • Redirection 19

Bottle Response • response 객체는 웹과 관련된 metadata들을 저장하고 설정할 수 있게 함 (http header, cookie 등) • 위 예제는 http protocol header의 Content-Language를 en으로 수정 20

Bottle Request • response와는 반대로 클라이언트 측에서 온 header, forms, cookie 등을 저장 21


Bottle Request • POST 방식으로 넘어온 http, form 데이터 처리 • GET 방식이면 query, POST면 forms 23

Bottle Request • 하위 속성 • <input type=“file”>을 통해 POST로 온 파일 저장 24


Bottle Template • 동적인 웹 페이지를 표현하기 위해 HTML과 같이 쓰이는 문법 • Bottle의 기본 template engine인 simple template을 제외하고 도 오픈소스 프로젝트인 Mako, Cheetah, Jinja 2 template 지원 • 본 강의에서는 simple template만 사용 • Inline expression : {{ … }} • Embedded python code : % or <% … %> 26

Bottle Template • Inline Expression • 어떤 Python 코드라도 사용 가능 • Embedded Python Code • 어떤 Python 코드라도 사용 가능 • Tab, Space 공백 구분이 안되므로 블록 마지막에 %end 필요 27

Bottle Template • Bottle 코드 • hello_template. tpl • Bottle 코드가 있는 파이썬 파일과 같은 폴더에 생성 28

- Slides: 29