Created
December 16, 2025 02:34
-
-
Save smzn/36f83eaf5d4de115b3def0e1cb1188db 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
| @app.route('/update/<int:id>', methods=['GET', 'POST']) | |
| def update(id): | |
| # 1. 編集したいデータをDBから取得 | |
| location = Location.query.get_or_404(id) | |
| # 2. ポスト送信されたら(保存ボタンが押されたら) | |
| if request.method == 'POST': | |
| # フォームのデータで上書きする | |
| location.name = request.form.get('name') | |
| location.latitude = request.form.get('latitude') | |
| location.longitude = request.form.get('longitude') | |
| # 変更を確定する (addは不要、commitだけでOK) | |
| db.session.commit() | |
| # 一覧に戻る | |
| return redirect(url_for('index')) | |
| # 3. ページを開いたときは、既存データ(location)を渡して編集画面を表示 | |
| return render_template('update.html', location=location) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment