Skip to content

Instantly share code, notes, and snippets.

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

  • Save smzn/36f83eaf5d4de115b3def0e1cb1188db to your computer and use it in GitHub Desktop.

Select an option

Save smzn/36f83eaf5d4de115b3def0e1cb1188db to your computer and use it in GitHub Desktop.
@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