博客
关于我
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/

你可能感兴趣的文章
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>