파이썬 flask로 hello world 웹페이지 작성
파이썬 flask로 간단한 웹페이지를 만드는 예시입니다. 우선 flask 모듈을 설치합니다. 우분투 계열 리눅스의 경우 아래와 같이 python3-flask 패키지를 설치해 주면 됩니다.
sudo apt-get install python3-flask
예제 코드는 매우 간단합니다.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def root_page():
return "hello world!"
@app.route('/test/')
def test_page():
return "test"
# 본 스크립트를 import하지 않고 직접 실행할 경우 flask 자체 웹서버 실행(포트 5000)
if __name__ == "__main__":
app.run(host='127.0.0.1', port=5000)
위와 같은 스크립트를 실행하면 웹서버가 구동되어 루프백(loopback) 주소(127.0.0.1)의 5000번 포트를 열게 됩니다. 루트 페이지(http://localhost:5000/)에 접속하면 문자열 "hello world!"가 표시되고, 테스트 페이지(http://localhost:5000/test/)에 접속하면 문자열 "test"가 표시됩니다.
어떤 페이지에 접속하면 어떤 내용을 표시해 줄 것인지를 위와 같이 함수를 정의하고 데코레이터(decorator)를 이용해서 웹 앱의 route() 함수가 해당 함수를 받아서 처리합니다.
@joviansummer의 스팀 프로젝트
스팀 증인노드를 운영중입니다. @jswit에 증인투표해 주시면 감사하겠습니다.
(https://steemitwallet.com/~witnesses)
jsup 서비스에 큐레이션 보상 분배 기능이 추가되었습니다.
jSTEEM 프로젝트 - 텔레그램 챗봇으로 구현하는 스팀 블럭체인 탐색기
Posted through the AVLE Dapp (https://avle.io)
Thank you, friend!


I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.
Upvoted! Thank you for supporting witness @jswit.