<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by YU-CHIA LIN on Medium]]></title>
        <description><![CDATA[Stories by YU-CHIA LIN on Medium]]></description>
        <link>https://medium.com/@s1061666?source=rss-b4b5893245a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*NQQuddYFk3AK4NpACcPglA.png</url>
            <title>Stories by YU-CHIA LIN on Medium</title>
            <link>https://medium.com/@s1061666?source=rss-b4b5893245a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:22:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s1061666/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Flask  —  Heroku 雲端主機]]></title>
            <link>https://medium.com/@s1061666/python-flask-heroku-%E9%9B%B2%E7%AB%AF%E4%B8%BB%E6%A9%9F-be0952bef235?source=rss-b4b5893245a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/be0952bef235</guid>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[python-flask]]></category>
            <dc:creator><![CDATA[YU-CHIA LIN]]></dc:creator>
            <pubDate>Sun, 05 May 2019 16:31:39 GMT</pubDate>
            <atom:updated>2019-05-06T09:20:43.620Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Flask — Heroku 雲端主機服務</h3><p><em>(本篇筆記參考於「</em><a href="https://www.youtube.com/watch?v=wWRYBUzEG6E&amp;t=830s"><em>彭彭老師</em></a><em>」的線上課程，歡迎過去觀賞更多課程~)</em></p><blockquote>在 <a href="https://medium.com/@s1061666/python-flask-%E7%B6%B2%E7%AB%99%E9%96%8B%E7%99%BC-%E7%92%B0%E5%A2%83%E5%BB%BA%E7%BD%AE-debf770727ac">前篇</a> 的介紹中，我們只能在電腦本機中測試，而這篇則是利用</blockquote><blockquote>&quot;Heroku 雲端主機&quot;</blockquote><blockquote>來達到實際上線的效果...</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*9KY5qUEzCYDR3dpdAuW7XQ.png" /><figcaption>先將<a href="https://medium.com/@s1061666/python-flask-%E7%B6%B2%E7%AB%99%E9%96%8B%E7%99%BC-%E7%92%B0%E5%A2%83%E5%BB%BA%E7%BD%AE-debf770727ac">前篇</a>中的 app.py 改成 app-run.py (後面會講到)</figcaption></figure><h4>首先，建立描述檔 runtime.txt (描述使用的 Python 環境)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*s_nHNJ8xH4DsQvdzBs-JpQ.png" /><figcaption>檔名不可變更，以免發生錯誤</figcaption></figure><p>若不知道自己所使用的 Python 版本的話可以在 Terminal 打上 &quot;python&quot; 確認</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPgXMlLX-OgWDCMFkRw-rA.png" /><figcaption>指令就是 &quot;python&quot;</figcaption></figure><h4>建立描述檔 requirements.txt (描述程式運作所需套件)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/1*eJ-yZZLE1baU3yc9_52tlw.png" /><figcaption>檔名一樣不可隨意更動，以免錯誤</figcaption></figure><p>接著我們便可新增我們所需的套件名稱</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0DUfMY-2hRj5_TxsLp1zA.png" /><figcaption>gunicorn 是為了讓我們能在 Heroku 上啟動程式所需的套件，所以是必須打上去的</figcaption></figure><h4>建立 Procfile 以告知 Heroku 如何執行程式</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*kTDaz5fW4XETHVEwB1KQiA.png" /><figcaption>Procfile 沒有副檔名</figcaption></figure><p>然後打上以下這行</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwKqdNqUzJk3my6N32dayw.png" /></figure><p>先來解釋一下各自的意思...</p><p>web =&gt; 告訴 Heroku 此專案是一個 web 專案</p><p>gunicorn =&gt; 告訴 Heroku 以此套件啟動專案</p><p>app-run =&gt; 待啟動的主要檔案名稱</p><p>app =&gt; app-run.py 檔案中的 app 變數</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxNJ9_aaEPLCeGoE_a6dVw.png" /></figure><h4>安裝 Git</h4><p>Google “Git” 就可以到他們的<a href="https://git-scm.com/">官網</a>進行下載</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vRTHEnvdxdOasXssGDjsw.png" /><figcaption>點擊畫圈處即可進行下載</figcaption></figure><p>後面的安裝過程就不贅述了，一直 next 就對了~</p><p><em>接著總算是輪到這次的主角登場啦~</em></p><h4>Heroku 雲端主機服務</h4><p>首先，請先進入<a href="https://www.heroku.com/">官網</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxYRCJMwo_BsdFCmO37TVQ.png" /></figure><p>接下來點選右上角的 &quot;Sign up&quot; 以註冊帳號</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnRWdlRtWCYDVn4QzGi4sw.png" /><figcaption>基本上除了 email 必須正確外其他都可隨意填</figcaption></figure><p>註冊成功且驗證成功後就直接登入</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3N10MEsnzeDkU_sxZJgBg.png" /></figure><p>點選 &quot;Create a new app&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3kEC4-nC-KIF-NpGEDbXg.png" /><figcaption>App name 可以隨意取</figcaption></figure><p>點選 &quot;Create app&quot; 後便會來到以下畫面</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvGvY9S4TlOl5eT0vDpPrw.png" /><figcaption>在這裡可以檢視專案狀態</figcaption></figure><p>然後往下面找一下就會發現 &quot;Heroku CLI&quot;，下載他，並安裝他</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAx0yBAo1uiBnhGgFXTUWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CkSwXcuohdVL9mXFsVANqw.png" /><figcaption>選擇對應版本安裝</figcaption></figure><p>安裝步驟一樣不贅述了，一直 next 就對了~</p><p>最後只要在打上以下的指令就完成部署囉!! <em>(接下來會說明如何打上指令)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dxlj6phCVC7YQsk0A72HGg.png" /></figure><h4>讓我們回到 VScode~</h4><blockquote>第一步 - 測試環境是否完整</blockquote><p>在 Terminal 打上 &quot;git&quot; , &quot;heroku&quot; 檢查這兩個工具是否安全地安裝完成了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*uxbxxvU7kUYImAoe05zntQ.png" /><figcaption>指令: &quot;git&quot; , 檢查 git 環境</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*JC-IhV3QMZmSMH28VHm7cg.png" /><figcaption>成功便會看到這些信息</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*QB4u9TBVbWIPEAY-9EyQgA.png" /><figcaption>指令: “heroku” , 檢查 heroku 環境</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NqBLnwTyACZVfbrGzH-eQ.png" /><figcaption>跟剛剛一樣，若成功便會看到一串介紹指令的信息</figcaption></figure><p><em>若在檢查過程中發現出錯，可以重開 VScode 看看</em></p><p><em>(如果該安裝的都有安裝的話)</em></p><blockquote>第二步 - 登入 heroku</blockquote><p>輸入指令 heroku login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*bLCk8c3P2x94FjTn0Hevkw.png" /><figcaption>登入 heroku</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*NmpLhQWUaYQ1Bxf0mPOhDw.png" /><figcaption>本次範例是會打開瀏覽器進行登入，但某些版本貌似是直接在 Terminal 中登入</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qjmf4RZiwR6pn10pluVErQ.png" /><figcaption>登入成功!!</figcaption></figure><blockquote>第三步 - 「初始化」專案</blockquote><p><em>(初始化只要在第一次部署時做一次就可以，往後若要繼續更新版本便不需重複這些動作)</em></p><p>輸入指令 git init</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*EyKn_Ony3FfzzVxyUo_6Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*W7SMRPQ7VQuJ2RaO9FeM4Q.png" /><figcaption>成功</figcaption></figure><p>輸入指令 heroku git:remote -a “heroku 專案名稱”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*S1LTgaCa_8odcg-_dQTyWA.png" /></figure><p>如果忘記自己專案名稱的話可以回到剛剛的頁面...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZMMDvR-6UaDwWjS3dMHzA.png" /><figcaption>找到後複製貼上即可</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*OJ_UkIoaz4huOV7e0NZoFQ.png" /><figcaption>成功</figcaption></figure><blockquote>第四步(最後) - 部署專案</blockquote><p>輸入指令 git add .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*xow4r6VGIuIkpV8WA-rN2w.png" /><figcaption>記得 add 後要加一個空格 =&gt; git + “ ” + add + “ ” + .</figcaption></figure><p>輸入指令 git commit -am “部署訊息”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*L1Hpjm5n68Gdhr_W7UonKQ.png" /><figcaption>deploy message 可以自行更改</figcaption></figure><p>輸入指令 git push heroku master</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*6Z4qQLo1xn-D1hU_h66dcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FgJIiSDpYCnhGoZ7lw-YnA.png" /><figcaption>成功</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yX6Q07Itfr5TcO4SX3b3hw.png" /><figcaption>點選即可進入正式部署後的網站~</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nM6TfAOGDMZwAj9NbZKZIg.png" /><figcaption>部署成功啦!!</figcaption></figure><p>成功部署後即可以該網址進行連網~</p><p>而若接下來想更新版本只要重複 &quot;第四步&quot; 即可~</p><blockquote>延伸 - 暫停 Heroku 服務</blockquote><p>當你今天有任何理由或需求想要暫停 Heroku 服務並且不想刪除專案的話...</p><p>輸入指令 heroku scale web=0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*jFPbNpEoBryTIOtMtZROfw.png" /></figure><p>接著，我們回到網站...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFkAyR1up5VRskCGvzykHQ.png" /><figcaption>這樣就成功暫停服務了</figcaption></figure><p>而若想回復也是相當簡單的</p><p>輸入指令 heroku scale web=1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*AmLNO8CCxGsA9hnDY3En1w.png" /></figure><p>再回到網站...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nM6TfAOGDMZwAj9NbZKZIg.png" /><figcaption>成功再啟動了</figcaption></figure><p>這次的筆記就到此結束，感謝觀看</p><p>[]~(▔▽▔)~*</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be0952bef235" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Flask 網站開發 - 環境建置]]></title>
            <link>https://medium.com/@s1061666/python-flask-%E7%B6%B2%E7%AB%99%E9%96%8B%E7%99%BC-%E7%92%B0%E5%A2%83%E5%BB%BA%E7%BD%AE-debf770727ac?source=rss-b4b5893245a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/debf770727ac</guid>
            <category><![CDATA[python-flask]]></category>
            <dc:creator><![CDATA[YU-CHIA LIN]]></dc:creator>
            <pubDate>Sat, 04 May 2019 15:53:09 GMT</pubDate>
            <atom:updated>2019-05-06T13:04:04.243Z</atom:updated>
            <content:encoded><![CDATA[<p><em>(本篇筆記參考於「</em><a href="https://www.youtube.com/watch?v=dYulda6wEWA"><em>彭彭老師</em></a><em>」的線上課程，歡迎過去觀賞更多課程~)</em></p><h4><strong>先建設一個專案資料夾並且以 VS code 開啟</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hTq0rsitYeieoZ6XwBdbw.png" /></figure><h4><strong>以 pip 安裝 flask</strong></h4><p><strong>(若是沒有安裝 pip 可以參考 </strong><a href="https://medium.com/@CCstruggled/python-%E5%AE%89%E8%A3%9D-pip-%E6%96%BC-windows-%E6%88%96-centos-%E7%B7%9A%E4%B8%8A-%E9%9B%A2%E7%B7%9A%E5%AE%89%E8%A3%9D-pip-101-fb6d8e3c611b"><strong>Tinderbox 大大的這篇</strong></a><strong>)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mix56_yWJp0MucvxsVrL6A.png" /><figcaption>指令: pip install flask</figcaption></figure><h4><strong>新增一 .py 檔案 (app.py)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNYVz8ZjFFkU3Dc5fIXyhQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e24590b6e7702685edde55822e8125c9/href">https://medium.com/media/e24590b6e7702685edde55822e8125c9/href</a></iframe><h4><strong>啟動 app.py</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*q1H_IXhb06ayZqWFTeKo7w.png" /><figcaption>打上指令 : python app.py</figcaption></figure><p>接著如果正常執行的話應該會長這樣...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*WtDToiY98Xy_T3w-onzvPg.png" /></figure><p>出現以上畫面即表示成功啟動並且會顯示出網址列</p><p>(此例為: <a href="http://127.0.0.1:5000/">http://127.0.0.1:5000/</a>)</p><p>接著就可以打開瀏覽器輸入該網址...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKybeN72BZh_AU1oHNXtzg.png" /></figure><p>並且當你看到網頁的同時也會同時得到連線紀錄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-S20oiLROZaW6Gwj9q_SxQ.png" /><figcaption>若想關閉伺服器則照指示在 Terminal 介面按下 CTRL+C 即可</figcaption></figure><h4><strong>處理網址列的變動</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHRdYUoHzCZo2illPchtUw.png" /><figcaption>“@app.route(‘/’)” 代表今天在根目錄時我們所執行的程序</figcaption></figure><p>因此若我們想處理更多網頁路徑的話，我們也可以自行新增</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBXYgWj9PftaZyNmEsVtUQ.png" /></figure><p>新增完後重新啟動伺服器，並且輸入網址: 127.0.0.1:5000/test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eavtXm66f6KIr3GnC9Frg.png" /></figure><p>即可看到輸出結果~</p><p>以上為 flask 的基本環境建置，感謝觀看 (๑´ㅂ`๑)</p><blockquote>接續 =&gt; <a href="https://medium.com/@s1061666/python-flask-heroku-%E9%9B%B2%E7%AB%AF%E4%B8%BB%E6%A9%9F-be0952bef235">Python Flask — Heroku 雲端主機服務</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=debf770727ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>