本周目標
Flask 網站開發
任務
- 基礎環境建置
- Heroku 雲端主機教學
專案練習
輸入git commit -am “make it better”顯示以下資訊
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
繼續輸入git push heroku main顯示錯誤
error: src refspec main does not match any
error: failed to push some refs to 'https://git.heroku.com/gemma-python.git'
ChatGPT顯示下列原因
- main分支不存在 網路教學式master
- 沒有提交代碼到本地任何分之
- 未設定遠端儲存庫或分之
- Heroku儲存初始化問題
我的解決方法
先講結論: Heroku網站已取消免費,可以轉移至Pythonanywhere
沒找到如何使用VS Code運行Pythonanywhere
但免費版無法自己創資料夾和檔案,只能測試上傳Code後網站可以正常運作
步驟1: 先確認設定檔無問題
檢查Procfile輸入錯字,更正後重新輸入git commit -am “make it better”依然有問題
步驟2: 確認分支名稱
輸入git branch,沒有顯示任何東西,代表沒有設定到分支名稱
步驟3: 設定分支名稱
輸入git branch -M main
步驟4: 確認 HEAD 是否指向某個分支
輸入cat .git/HEAD 確定到main
ref: refs/heads/main
但重複設定步驟依然顯示*** Please tell me who you are.
步驟5: 設定名字
git config --global user.name "Gemma"
>> git config --global user.email "yabahong@gmail.com"
輸入git config –global –list 確認已登錄名字跟信箱
user.name=Gemma
user.email=yabahong@gmail.com
再次嘗試git commit -m “Your commit message”
沒有顯示*** Please tell me who you are.
步驟6: 測試git push heroku main
這之前可以先檢查自己的分支名稱git branch顯示名稱,我的顯示mian
但彭彭老師繳學影片為master,所以也可能是分支名稱的問題
[main (root-commit) 0267e69] Your commit message
4 files changed, 57 insertions(+)
create mode 100644 Procfile
create mode 100644 app.py
create mode 100644 requirements.txt
create mode 100644 tontime.txt
#(以下省略)
結果: 出現Application Error
程式可以跑,但跑出來網址有問題
轉移到Pythonanywhere已可以成功展示網站