Created
December 16, 2025 02:22
-
-
Save smzn/4d368c199170e99f3b740e11dc78364a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # <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