AssertionError: View function mapping is overwriting an existing endpoint functionの対応
以上を参考
Flaskで上記のエラーが発生したため
原因
ref の場合
code:Python
@app.route('/addEvent/', methods='POST') def addEvent():
@app.route('/deleteEvent/', methods='POST') def addEvent()
上記でAssertionerrorが発生していたが、問題はdef addEvent(): が二つあること。
The endpoint name is normally taken from the function you decorated with @app.route(); you can also explicitly give your endpoint a different name by telling the decorator what name you'd want to use instead:
code:Python
@app.route('/deleteEvent/', methods='POST', endpoint='deleteEvent') def addEvent():
which would let you stick to using the same name for the function. In this specific case, that's not a good idea, because one function replaced the other and the only reference left to the first is in the Flask URL map.
要するに、functionの名前は異なるものにしないとエンドポイントの名前が与えられないため(デコレータからエンドポイント名を取得するから)。一方のfunctionで上書きしてるから、片方しかURLに参照されていないため。
自分のコードだとこう
code:Python
@app.route('/images/<path:filepath>')
def send_js(filepath):
return send_from_directory(SAVE_DIR, filepath)
@app.route('/static/pfm_img/<path:fragrance>')
def send_js(fragrance):
return send_from_directory(SAVE_DIR_2, fragrance)
全く同じミスをしていることがわかる。
解決法
code:Python
@app.route('/images/<path:filepath>')
def send_js(filepath):
return send_from_directory(SAVE_DIR, filepath)
@app.route('/static/pfm_img/<path:fragrance>')
def send_js_2(fragrance):
return send_from_directory(SAVE_DIR_2, fragrance)
に変更した。