Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 배우기

Flask 본문

카테고리 없음

Flask

새싹싹이 2023. 9. 20. 10:44

Blueprint

URL과 함수의 매핑을 관리하기 위해 사용하는 도구

라우팅 경로 지정

 


__init__.py

from flask import Flask
def create_app():
    app = Flask(__name__)

    from .views import main_views
    app.register_blueprint(main_views.bp)

    return app​

main_views.py

from flask import Blueprint

bp = Blueprint('main', __name__, url_prefix='/')


@bp.route('/hello')
def hello_pybo():
    return 'Hello, Pybo!'


@bp.route('/')
def index():
    return 'Pybo index'

/hello라는 blueprint로 연결

<<참고>>ctrl + 파일명 클릭하면 연결 파일 열림