Skip to content

Instantly share code, notes, and snippets.

@smzn
Created December 16, 2025 02:22
Show Gist options
  • Select an option

  • Save smzn/4d368c199170e99f3b740e11dc78364a to your computer and use it in GitHub Desktop.

Select an option

Save smzn/4d368c199170e99f3b740e11dc78364a to your computer and use it in GitHub Desktop.
# <int:id> は「URLのこの部分を整数の id という変数で受け取る」という意味です
@app.route('/delete/<int:id>', methods=['POST'])
def delete(id):
# 1. 指定されたIDのデータを探す (なければ404エラーを出す便利機能)
location = Location.query.get_or_404(id)
# 2. 削除処理をステージング
db.session.delete(location)
# 3. コミット (DBに反映)
db.session.commit()
# 4. 一覧に戻る
return redirect(url_for('index'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment