このコードを適用して、テーブルから id を取得しました。
getItemid=cursor.execute("Select id from shop_carthistory where order_id =%s",[order.order_number])
row=cursor.fetchall()
context = {order_id": row }
{{order_id}} gives => ((37L,),)
そのうち37個しか必要ありません