博客
关于我
beego自定义404、401、403、500、503等页面
阅读量:657 次
发布时间: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性能测试工具选择 mysql软件测试
查看>>
mysql恢复root密码
查看>>
Mysql悲观锁
查看>>
MySQL慢查询-开启慢查询
查看>>
MySQL慢查询分析和性能优化的方法和技巧
查看>>
MySQL慢查询日志总结
查看>>
Mysql慢查询日志,查询截取分析
查看>>
MySQL慢查询问题排查
查看>>
mysql截取sql语句
查看>>
mysql截取身份证号前几位_EXCEL中怎样截取身份证号前六位数字
查看>>
mysql手工注入
查看>>
MySQL执行SQL文件出现【Unknown collation ‘utf8mb4_0900_ai_ci‘】的解决方案
查看>>
Mysql执行update by id的过程
查看>>
mysql执行计划
查看>>
MySQL执行计划 EXPLAIN参数
查看>>
MySQL执行计划【explain】,看这一篇就够啦!
查看>>
Mysql执行计划字段解释
查看>>
mysql执行计划怎么看
查看>>
MySQL执行计划解读
查看>>