在此代码中,我有两条消息。
1-第一个是注册您的帐户已创建。现在登录到一个帐户,然后
2-第二个是登录失败,即如果电子邮件或密码不匹配,则给出错误消息。
我已经在文件中调用了这两条消息,但是当我运行此代码时,它更喜欢只运行第一条消息。login.html
<div class="loginfailure">
<h1>{{.Loginfailure}}</h1>
</div>
它不允许第二个消息,如果调用第二条消息,它将提供空白页。
处理程序.go
注册成功
success := struct{ Signupsuccess string }{Signupsuccess: "Your account is successfully created"}
loginTmpl.Execute(w, success)
登录失败
failure := struct{ Loginfailure string }{Loginfailure: "Enter the correct email or password"}
loginTmpl.Execute(w, failure)
登录.html
{{define "body"}}
<div class="loginfailure">
<h1>{{.Loginfailure}}</h1>
</div>
<div class="signupsuccess">
<h1>{{.Signupsuccess}}</h1>
</div>
<h1>Log In</h1>
<p>Login to access your account</p>
<form action="/login" method="POST">
<div>
<label for="email">Email</label>
<input type="email" name="email" placeholder="Enter your email address" required>
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" placeholder="Enter your password" required>
</div>
<div>
<input type="submit" value="Login">
</div>
<div>
<a href="/signup" class="link">Signup</a>
</div>
</form>
{{end}}
喵喵时光机
相关分类