๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

TIL/ETC

AttributeError: module 'calendar' has no attribute 'bp'

blueprint ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ calendar.py ํŒŒ์ผ์„ app.py์— import ํ•˜๋Š” ๊ณผ์ •์—์„œ ์—๋Ÿฌ ๋ฐœ์ƒ

 

calendar.py ํŒŒ์ผ ์ƒํƒœ

from flask import Blueprint

bp = Blueprint("calendar", __name__), url_prefix="/calendar")


@bp.route('/calendar',methods=['GET','POST'])
def calendar():
    return render_template("calendar.html")

 

app.py ์ƒํƒœ

 

with app.app_context():
    import calendar #calendar.py๋ฅผ ์ž„ํฌํŠธ
    app.register_blueprint(calendar.bp)

 

ํ•ด๊ฒฐ

bp ์ด๋ฆ„(Blueprint("calendar"))๊ณผ ํŒŒ์ด์ฌํŒŒ์ผ ์ด๋ฆ„(calendar.py)์ด ๊ฐ™์•„์„œ๋Š” ์•ˆ๋จ.

๋‘˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™