博客
关于我
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 ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>