Python+Flaskに、ORMのSQLAlchemyを設定、プライマリーキーでデータを取得です。get(id)が基本で、get_or_404(id)だと、データが見つからない場合、404を返してくれるらしい。
実際に設定してみたのがこちら。
参考サイト
Select, Insert, Delete(Flask-SQLAlchemy Documentation)
Python+Flaskに、ORMのSQLAlchemyを設定
@app.route('/blog/<int:blog_id>')
def show_blog(blog_id):
entry = Entry.query.get_or_404(blog_id)
return render_template('show_blog.html', entry=entry)
実際に設定してみたのがこちら。
参考サイト
Select, Insert, Delete(Flask-SQLAlchemy Documentation)
Python+Flaskに、ORMのSQLAlchemyを設定