Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.1节login方法代码错误 #1121

Open
bigeye0623 opened this issue Dec 29, 2019 · 1 comment
Open

4.1节login方法代码错误 #1121

bigeye0623 opened this issue Dec 29, 2019 · 1 comment

Comments

@bigeye0623
Copy link

4.1 节代码

func login(w http.ResponseWriter, r *http.Request) {
	fmt.Println("method:", r.Method) //获取请求的方法
	if r.Method == "GET" {
		t, _ := template.ParseFiles("login.gtpl")
		log.Println(t.Execute(w, nil))
	} else {
		//请求的是登录数据,那么执行登录的逻辑判断
		fmt.Println("username:", r.Form["username"])
		fmt.Println("password:", r.Form["password"])
	}
}

缺少:

r.ParseForm()

所以函数打印的usernamepassword一直为空。

@bigeye0623
Copy link
Author

不好意思,没有看到这就是个错误例子。

@bigeye0623 bigeye0623 reopened this Dec 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant