2

I redefined the page_not_found on router.go,

func page_not_found(rw http.ResponseWriter, r *http.Request) {
    t, _ := template.ParseFiles(beego.ViewsPath + "/404.html")
    data := make(map[string]interface{})

    t.Execute(rw, data)
}

and in init function used

beego.Errorhandler("404", page_not_found)

when i called 404 by used this.Abort("404") in controller, the 404 page was not show html, it showed the page html text, liked this

html text/plain

4

1 回答 1

1

because i wrote 404 html liked this

<link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/a.css">
<div class="html404">
    <div class="title">404</div>
        <div class="link">
            <div><a href="/">回首页&lt;/a>
            </div>
        </div>
    </div>
</div>

it caused the question. when i changed the html to

<html>

<head>
     <title>Aiysea 404 Page</title><link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/a.css">
</head>

<body>

    <div class="html404">
        <div class="title">404</div>
            <div class="link">
                <div><a href="/">回首页&lt;/a>
                 </div>
            </div>
        </div>
   </div>
</body>

</html>

then it gone well.

于 2014-10-24T08:34:07.047 回答