跳到主要內容

python自帶的簡易網頁伺服器

  開發angular.js時,因為引用外部文件導致Chrome的Console報錯。訊息:Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https。簡單地說,就是這種操作文件方式,只支援在使用http, , data, chrome-extension, https協議時。
  
  為了解決這個問題,可以將你的文件放到一個網頁伺服器上。Python剛好有一個自帶的網頁伺服器,下面是具體操作的方法:
  1. 下載安裝Python 3.6.3到Windows10作業系統中。
  2. WIN+R輸入cmd開啟console。
  3. 切換到網頁所在路徑,舉例:網頁位於Foo\index.html,輸入cd Foo<ENTER>
  4. 輸入python -m http.server啟動網頁伺服器。
  5. 開啟Chrome在路徑列中輸入http://127.0.0.1:8000/index.html,就能看到你的首頁。

捷徑

  可以在桌面建立捷徑,就不必每次都打指令。具體操作的方法如下:
  1. 在網頁所在路徑下,編輯一檔案名為start_web_server.bat。
  2. 檔案內容為
  3. @echo off
  4. python -m http.server
  5. 在檔案上按右鍵開啟選單 Send to| Desktop (Create shortcut)

參考

留言

這個網誌中的熱門文章

如何學習英語聽的技能

有三個理由需要考慮: 1. 甚麼令你難以理解? 很多音相似 舉例: boat -bought mad -mud hurt -heart men-main than-then bit-bet live-leave 有很多音會黏再一起 how is it going? -> how 'zit going? 語言模式1 合同動詞和否定 i'm he's they'll we've won't can't  O.K. I'll do it. (不強調I'll:無特殊情緒) I will do it. nothing can stop me. (強調will:顯示決心) 在正式的文件儘量用完整的句子,不要用縮寫 語言模式2 弱形式 例子 I can ski -> I kn ski 母音消失 here's my book->here's m[ə]   book it's for you -> it's f[ə] you 語言模式3 子音連結 he works as an engineer-> he work sazanen gineer she is interested in it->she (y)isinterestedinit . they went to an amazing place->they went to(w)anamazing place 聽寫,比對影片上的字幕是否一樣 2.改善你的發音 發音的陷阱1: 一樣的拼音不等於一樣的發音 ea -> /i:/ (jean)  -great  -hear  -learn  -instead 發音的陷阱2: 字的重音 哪個音節是重音? DEV elopment or de VEL opment or deve LOP ment or develop MENT 第二個才正確 下面的字發音可能相同 propose & purpose pro POSE & PUR pose 3.用耳朵聽,而不是用眼