博客
关于我
beego自定义404、401、403、500、503等页面
阅读量:656 次
发布时间:2019-03-15

本文共 934 字,大约阅读时间需要 3 分钟。

beego 框架默认支持 404、401、403、500、503 这几种错误的处理。用户可以自定义相应的错误处理,从1.4.3版本开始,支持Controller方式定义Error错误处理函数:

step1;在main方法在加入

beego.ErrorController(&controllers.ErrorController{})

在这里插入图片描述

step2:新建一个Error控制器

package controllersimport "github.com/astaxie/beego"/**  该控制器处理页面错误请求 */type ErrorController struct {	beego.Controller}func (c *ErrorController) Error401() {	c.Data["content"] = "未经授权,请求要求验证身份"	c.TplName="error/401.tpl"}func (c *ErrorController) Error403() {	c.Data["content"] = "服务器拒绝请求"	c.TplName="error/403.tpl"}func (c *ErrorController) Error404() {	c.Data["content"] = "很抱歉您访问的地址或者方法不存在"	c.TplName="error/404.tpl"}func (c *ErrorController) Error500() {	c.Data["content"] = "server error"	c.TplName = "error/500.tpl"}func (c *ErrorController) Error503() {	c.Data["content"] = "服务器目前无法使用(由于超载或停机维护)"	c.TplName = "error/503.tpl"}

step3: 在views新建一个error目录,并在目录添加对应文件,这里以404页面为主

    
404

{ {.content}}

step4:实际运行beego项目进行访问测试

在这里插入图片描述
大功告成

转载地址:http://dqvmz.baihongyu.com/

你可能感兴趣的文章
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>