<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                我們在前面已經講過如何處理靜態文件,這小節我們詳細的介紹如何在beego里面設置和使用靜態文件。通過再介紹一個twitter開源的html、css框架bootstrap,無需大量的設計工作就能夠讓你快速地建立一個漂亮的站點。 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/14.1.md#beego靜態文件實現和設置)beego靜態文件實現和設置 Go的net/http包中提供了靜態文件的服務,`ServeFile`和`FileServer`等函數。beego的靜態文件處理就是基于這一層處理的,具體的實現如下所示: ~~~ //static file server for prefix, staticDir := range StaticDir { if strings.HasPrefix(r.URL.Path, prefix) { file := staticDir + r.URL.Path[len(prefix):] http.ServeFile(w, r, file) w.started = true return } } ~~~ StaticDir里面保存的是相應的url對應到靜態文件所在的目錄,因此在處理URL請求的時候只需要判斷對應的請求地址是否包含靜態處理開頭的url,如果包含的話就采用http.ServeFile提供服務。 舉例如下: ~~~ beego.StaticDir["/asset"] = "/static" ~~~ 那么請求url如`http://www.beego.me/asset/bootstrap.css`就會請求`/static/bootstrap.css`來提供反饋給客戶端。 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/14.1.md#bootstrap集成)bootstrap集成 Bootstrap是Twitter推出的一個開源的用于前端開發的工具包。對于開發者來說,Bootstrap是快速開發Web應用程序的最佳前端工具包。它是一個CSS和HTML的集合,它使用了最新的HTML5標準,給你的Web開發提供了時尚的版式,表單,按鈕,表格,網格系統等等。 * 組件   Bootstrap中包含了豐富的Web組件,根據這些組件,可以快速的搭建一個漂亮、功能完備的網站。其中包括以下組件:   下拉菜單、按鈕組、按鈕下拉菜單、導航、導航條、面包屑、分頁、排版、縮略圖、警告對話框、進度條、媒體對象等 * Javascript插件   Bootstrap自帶了13個jQuery插件,這些插件為Bootstrap中的組件賦予了“生命”。其中包括:   模式對話框、標簽頁、滾動條、彈出框等。 * 定制自己的框架代碼   可以對Bootstrap中所有的CSS變量進行修改,依據自己的需求裁剪代碼。 [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.1.bootstrap.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.1.bootstrap.png?raw=true) 圖14.1 bootstrap站點 接下來我們利用bootstrap集成到beego框架里面來,快速的建立一個漂亮的站點。 1. 首先把下載的bootstrap目錄放到我們的項目目錄,取名為static,如下截圖所示 [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.1.bootstrap2.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.1.bootstrap2.png?raw=true) 圖14.2 項目中靜態文件目錄結構 2. 因為beego默認設置了StaticDir的值,所以如果你的靜態文件目錄是static的話就無須再增加了: StaticDir["/static"] = "static" 3. 模板中使用如下的地址就可以了: ~~~ //css文件 <link href="/static/css/bootstrap.css" rel="stylesheet"> //js文件 <script src="/static/js/bootstrap-transition.js"></script> //圖片文件 <img src="/static/img/logo.png"> ~~~ 上面可以實現把bootstrap集成到beego中來,如下展示的圖就是集成進來之后的展現效果圖: [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.1.bootstrap3.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.1.bootstrap3.png?raw=true) 圖14.3 構建的基于bootstrap的站點界面 這些模板和格式bootstrap官方都有提供,這邊就不再重復貼代碼,大家可以上bootstrap官方網站學習如何編寫模板。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看