英文:
How to Create Form Template in Go Programming?
问题
如何在Go编程中创建登录表单(用户名和密码)模板?
英文:
How to Create Login Form (username and Password) Template in Go Programming?
答案1
得分: 1
使用template在appengine上只有在传递html字段时才可能,因为根据appengine的规则,您无法访问文件系统。
这是一个示例:
const loginTemplateHTML = `<html>
<body>
<form action="/login" method="post">
<div><input name="username" type="text" /></div>
<div><input name="password" type="password" /></div>
<div><input type="submit" value="login"></div>
</form>
</body>
</html>
`
var loginTemplate = template.Must(template.New("Login").Parse(loginTemplateHTML))
func login (w http.ResponseWriter, r *http.Request) {
if err := loginTemplate.Execute(w,nil); err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
}
}
英文:
using template on appengine is only posible if you pass the html from field, because of appengine rules you dont have access to the filesystem
here is an example
const loginTemplateHTML = `<html>
<body>
<form action="/login" method="post">
<div><input name="username" type="text" /></div>
<div><input name="password" type="password" /></div>
<div><input type="submit" value="login"></div>
</form>
</body>
</html>
`
var loginTemplate = template.Must(template.New("Login").Parse(loginTemplateHTML))
func login (w http.ResponseWriter, r *http.Request) {
if err := loginTemplate.Execute(w,nil); err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论