我无法从 HTML 表单中获取数据。该模板显示在 localhost:3000,我提交并被带到 localhost:3000/results,结果显示“404 页面未找到”。URL 不包括任何表单字段。
package main
import (
"html/template"
"net/http"
"github.com/go-martini/martini"
)
func main() {
m := martini.Classic()
m.Get("/", func(res http.ResponseWriter, req *http.Request) { // res and req are injected by Martini
t, _ := template.ParseFiles("form.gtpl")
t.Execute(res, nil)
})
m.Get("/results", func(r *http.Request) string {
text := r.FormValue("text")
return text
})
m.Run()
}
模板是:form.gtpl
<html>
<head>
<title>Title Here</title>
</head>
<body bgcolor="#E6E6FA">
<h1>Header Here</h1>
<form action="/results" method="POST">
Date: <input type="text" name="dated" size="10" value="01/12/2015">
Triggers: <input type="text" name="triggers" size="100" value="Trigger1|Trigger2"><br><br>
<textarea name ="text" rows="20" cols="150">random text here
</textarea>
<input autofocus type="submit" value="Submit">
</form>
</body>
</html>
倚天杖
相关分类