shop_platform - 部署到 Heroku 後,session 有問題
問題描述 部署到 heroku 後,出現一些奇怪的現象: 輸入正確登入資訊,按下登入按鈕後: 有時候會登入成功,跳轉到首頁,但切換幾個畫面後,又變成沒有登入的狀態 跳轉到首頁,但仍是未登入狀態,也沒有出現任何 flash 訊息。切換幾個畫面後,出現遲來的 flash 訊息 仍是跳轉到登入頁面,沒有出現任何 flash 訊息 在未登入狀態下,將物品加入購物車(此時購物車內容會存在 session)。點選購物車頁面後: 有時候會跳轉到首頁,也沒有出現任何 flash 訊息。切換幾個畫面後,出現遲來的 flash 訊息 成功顯示購物車中的商品,但若繼續點選購物車頁面,過沒多久就提示「購物車中沒有商品」 上述操作(導覽列判斷使用者是否已登入、flash、未登入時的購物車),多半是跟 session 有關係,讓我有一種「cookie 或 session 好像會突然出現,又突然消失」的感覺。 另外,如果在本地也跟 heroku 一樣使用 gunicorn "app:create_app()" 指令開啟伺服器,一切功能都正常,無法重現 heroku 上的問題。 查資料 Flask sessions not persisting on heroku - stackoverflow Application Server、WSGI Server、Web Server 之間的關係 nginx+gunicorn/uwsgi+python web 的前世今生 Flask想上線? 你還需要一些酷東西 Heroku gunicorn flask login is not working properly - stackoverflow gunicorn 19 with WebSocket on Heroku These applications based on the Flask-SocketIO extension are stateful. If multiple workers ar...