跳到主要內容

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)

參考

留言

這個網誌中的熱門文章

幸福生活的三要點

自己想做且舒心的事最重要 不攀比 別想應做什麼,而是思考想做什麼 攀比,那會成就別人的心願,做不了自己。像在 自信的七個秘訣 中提到的,回應方式不知不覺的改變自己的思考,是不是過於順從,跟別人統一一致的行動,只要稍加模仿就能辦到。那不用大腦很輕鬆,行動久了一部分久沒用的機能就會退化,像老人的記憶退化症。一致的行動就像機器人一樣呆板,沒有自己獨特的想法,用其他機器人就能取代了。 參考 極簡生活:簡而美地活

在Windows 10/8/7/Vista/XP中用shell指令存取特殊資料夾

特殊資料夾的位置定義在註冊表中 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\FolderDescriptions Windows 10的完整shell:指令列表 shell:AccountPictures shell:Roaming Tiles shell:Common Programs shell:PublicAccountPictures shell:GameTasks shell:UserProfiles shell:MyComputerFolder shell:SearchHistoryFolder shell:Local Pictures shell:SyncSetupFolder shell:DpapiKeys shell:Retail Demo shell:Favorites shell:My Video shell:SearchHomeFolder shell:RecordedTVLibrary shell:System shell:Libraries shell:ThisDeviceFolder shell:AppsFolder shell:MusicLibrary shell:CommonVideo shell:OneDriveDocuments shell:SyncResultsFolder shell:Cookies shell:CameraRollLibrary shell:Original Images shell:Recorded Calls shell:3D Objects shell:CommonMusic shell:OneDrivePictures shell:My Pictures shell:Cache shell:Local Videos shell:Downloads shell:SavedPictures shell:CommonDownloads shell:AppData shell:SyncCenterFolder shell:PublicLibraries shell:VideosLibrary shell:My Mus...