fix the example error
Showing
1 changed file
with
3 additions
and
3 deletions
| ... | @@ -504,14 +504,14 @@ XML数据直接输出,设置`content-type`为`application/xml`: | ... | @@ -504,14 +504,14 @@ XML数据直接输出,设置`content-type`为`application/xml`: |
| 504 | beego框架默认支持404、401、403、500、503这几种错误的处理。用户可以自定义相应的错误处理,例如下面重新定义404页面: | 504 | beego框架默认支持404、401、403、500、503这几种错误的处理。用户可以自定义相应的错误处理,例如下面重新定义404页面: |
| 505 | 505 | ||
| 506 | func page_not_found(rw http.ResponseWriter, r *http.Request){ | 506 | func page_not_found(rw http.ResponseWriter, r *http.Request){ |
| 507 | t:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"404.html") | 507 | t,_:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"/404.html") |
| 508 | data :=make(map[string]interface{}) | 508 | data :=make(map[string]interface{}) |
| 509 | data["content"] = "page not found" | 509 | data["content"] = "page not found" |
| 510 | t.Execute(rw, data) | 510 | t.Execute(rw, data) |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | func main() { | 513 | func main() { |
| 514 | beego.Errorhandler("404",PageNotFound) | 514 | beego.Errorhandler("404",page_not_found) |
| 515 | beego.Router("/", &controllers.MainController{}) | 515 | beego.Router("/", &controllers.MainController{}) |
| 516 | beego.Run() | 516 | beego.Run() |
| 517 | } | 517 | } |
| ... | @@ -521,7 +521,7 @@ beego框架默认支持404、401、403、500、503这几种错误的处理。用 | ... | @@ -521,7 +521,7 @@ beego框架默认支持404、401、403、500、503这几种错误的处理。用 |
| 521 | beego更加人性化的还有一个设计就是支持用户自定义字符串错误类型处理函数,例如下面的代码,用户注册了一个数据库出错的处理页面: | 521 | beego更加人性化的还有一个设计就是支持用户自定义字符串错误类型处理函数,例如下面的代码,用户注册了一个数据库出错的处理页面: |
| 522 | 522 | ||
| 523 | func dbError(rw http.ResponseWriter, r *http.Request){ | 523 | func dbError(rw http.ResponseWriter, r *http.Request){ |
| 524 | t:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"dberror.html") | 524 | t,_:= template.New("beegoerrortemp").ParseFiles(beego.ViewsPath+"/dberror.html") |
| 525 | data :=make(map[string]interface{}) | 525 | data :=make(map[string]interface{}) |
| 526 | data["content"] = "database is now down" | 526 | data["content"] = "database is now down" |
| 527 | t.Execute(rw, data) | 527 | t.Execute(rw, data) | ... | ... |
-
Please register or sign in to post a comment