我想在beego下使用captcha生成验证码。但是它有错误invalid memory address or nil pointer dereference。有谁知道如何解决这个问题?谢谢。
Request Method: GET
Request URL: /accounts/forgotpassword
RemoteAddr: 127.0.0.1
Stack
C:/Go/src/runtime/asm_amd64.s:573
C:/Go/src/runtime/panic.go:505
C:/Go/src/text/template/exec.go:137
C:/Go/src/runtime/asm_amd64.s:573
C:/Go/src/runtime/panic.go:505
C:/Go/src/runtime/panic.go:63
我的代码: conf\app.conf
# Cache Provider
CacheProvider = redis
CacheConnection = {"conn":"127.0.0.1:6379"}
控制器\main.go
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/utils/captcha"
)
var(
cpt *captcha.Captcha
CacheProvider string = beego.AppConfig.String("CacheProvider")
CacheConnection string = beego.AppConfig.String("CacheConnection")
)
func init() {
store, _ := cache.NewCache(CacheProvider, CacheConnection)
cpt = captcha.NewWithFilter("/accounts/captca/", store)
}
视图\忘记密码控制器\get.tpl
<div class="w3-container w3-center">
<form method="post" id="mainForm"class="w3-container" style="margin-top:90px">
<div class="w3-card " style=" padding-left: 0px;
padding-right: 0px; margin-top: 30px;">
<div class="w3-container">
<h1>Reset password</h1>
</div><div class="w3-container" style=" padding-bottom: 16px;">
{{create_captcha}}
<input type="text" class="w3-input "name="captcha"style="outline: none;">
<p style="text-align: left;margin-top: 0px;color:red">
{{if .Errors.Captcha}}
{{.Errors.Captcha}}{{else}}‌{{end}}</p>
<input type="submit" value="Request reset password" onclick="login()" class="w3-button w3-indigo w3-block w3-round-large">
</div>
</div>
</form>
</div>
拉风的咖菲猫
相关分类