기본 콘텐츠로 건너뛰기

[Python, Flask] Flask 처음 시작해보기

[Python, Flask] Flask 처음 시작해보기

[Python, Flask] Flask 처음 시작해보기

from flask import Flask app = Flask(__name__)

@app.route( '/' ) def hello_world(): return 'Hello, World!'

@app.route( '/user/' ) def show_user_profile(username): # show the user profile for that user return 'User %s' % username

@app.route( '/post/' ) def show_post(post_id): # show the post with the given id, the id is an integer return 'Post %d' % post_id

@app.route( '/path/' ) def show_subpath(subpath): # show the subpath after /path/ return 'Subpath %s' % subpath

PS \python\flask> set FLASK_APP=flask_exam01.py

PS \python\flask> $env:FLASK_APP = 'flask_exam01.py'

PS \python\flask> set FLASK_ENV=development

PS \python\flask> flask run

* Serving Flask app "flask_exam01.py"

* Environment: production

WARNING: Do not use the development server in a production environment.

Use a production WSGI server instead.

* Debug mode: off

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

-> 브라우저를 띄워서 아래 URL로 테스트를 해보면 간단하게 결과를 알수 있다.

http://localhost:5000/

http://localhost:5000/user/kim

http://localhost:5000/post/1234

http://localhost:5000/path/test/sd/f/d

Converter types:

string (default) accepts any text without a slash int accepts positive integers float accepts positive floating point values path like string but also accepts slashes uuid accepts UUID strings

from http://fenderist.tistory.com/99 by ccl(A) rewrite - 2020-03-06 10:20:19

댓글

이 블로그의 인기 게시물

Flask 13. pythonanywhere에 배포하기

Flask 13. pythonanywhere에 배포하기 Login: PythonAnywhere It's always a pleasure to hear from you! Ask us a question, or tell us what you love or hate about PythonAnywhere. We'll get back to you over email ASAP. Sorry, there was an error connecting to the server. Please try again in a few moments... www.pythonanywhere.com from http://ohdowon064.tistory.com/124 by ccl(A) rewrite - 2020-03-11 15:54:10

Flask.py #1 설치해보자

Flask.py #1 설치해보자 Flask는 python의 프레임워크라고 할 수 있습니다. Flask를 설치해보자! # 리눅스 -- 접기 이러면 끝 - # pip install flask $ sudo -s 리눅스 같은 경우는 이미 파이썬이 설치가 되어 있을겁니다. # 리눅스 -- 접기 # 맥 -- 접기 이러면 끝 - $ sudo pip install flask 설치가 끝낫으면 Terminal.app 을 열어줍시다. 로 접속하여 파이썬을 설치해 줍니다. [ https://www.python.org/ ] # 맥 -- 접기 # 윈도우 -- 접기 [ https://www.python.org/ ] 로 접속하여 파이썬을 설치해 줍니다. 설치가 끝났으면 [ 고급설정 ] - [ 환경변수 ] - [ 시스템 변수 ] 에서 Path를 찾아줍니다. Path를 찾으셧다면 편집을 누르고 파이썬의 설치 경로와 파이썬 폴더 내의 Script 폴더를 입력해 줍시다. 환경변수까지 끝나셧다면 cmd 창을 키시고 pip install flask 이러면 flask 설치가 끝나게 됩니당 from http://chocoweb.tistory.com/14 by ccl(A) rewrite - 2020-03-07 13:54:54