出现了一个文章里没有的情况
相关信息:
- 类型:教程文章
- 文章: 创建博文
- 课程: 《G01 Go 实战:Web 入门(1.17)》
此投稿状态为 标记为已读。
标题修改:
内容修改:
| Old | New | Differences |
|---|---|---|
| 135 | 135 | ``` |
| 136 | 136 | |
| 137 | 137 | 保存后将编译成功,浏览器访问 http://localhost:3000/articles/create ,可见: |
| 138 | 此时,会出现另一个错误: | |
| 138 | 139 | |
| 140 |  | |
| 141 | 原因是:表单提交地址使用了一个不存在的路由: | |
| 142 | storeURL, _ := router.Get("articles.store").URL() | |
| 143 | 所以需要补一个articles.store的路由和函数: | |
| 144 | ``` | |
| 145 | router.HandleFunc("/articles/store", articlesStoreHandler).Methods("GET").Name("articles.store") | |
| 146 | ``` | |
| 147 | ``` | |
| 148 | func articlesStoreHandler(w http.ResponseWriter, r *http.Request) { | |
| 139 | 149 | |
| 150 | fmt.Fprint(w, "保存文章") | |
| 151 | ||
| 152 | } | |
| 153 | ``` | |
| 154 | 保存后将编译成功,浏览器访问 http://localhost:3000/articles/create ,可见: | |
| 140 | 155 |  |
| 141 | 156 | |
| 142 | 157 | 浏览器上右键,查看源码: |
关于 LearnKu