英文:
beego, redefined page not found, 404 page is not show html, why?
问题
我在router.go文件中重新定义了page_not_found
函数:
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)
}
在init
函数中使用了:
beego.Errorhandler("404", page_not_found)
当我在控制器中使用this.Abort("404")
调用404页面时,404页面没有显示HTML,而是显示了页面的HTML文本,类似于这样:
英文:
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
答案1
得分: 1
因为我写了这样的404页面:
<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="/">回首页</a></div>
</div>
</div>
这导致了问题。当我将HTML更改为:
<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="/">回首页</a>
</div>
</div>
</div>
</div>
</body>
</html>
然后问题就解决了。
英文:
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="/">回首页</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="/">回首页</a>
</div>
</div>
</div>
</div>
</body>
</html>
then it gone well.
评论