質問編集履歴
3
db.GetErrors()によるDBエラーの確認
test
CHANGED
File without changes
|
test
CHANGED
@@ -234,4 +234,44 @@
|
|
234
234
|
|
235
235
|
```
|
236
236
|
|
237
|
+
DBエラーの確認
|
238
|
+
|
239
|
+
```Go
|
240
|
+
|
241
|
+
func UserIndex(c web.C, w http.ResponseWriter, r *http.Request) {
|
242
|
+
|
243
|
+
Users := []models.User{}
|
244
|
+
|
245
|
+
fmt.Printf("%+v\n", Users)
|
246
|
+
|
247
|
+
db.Find(&Users)
|
248
|
+
|
249
|
+
db.GetErrors() //追加
|
250
|
+
|
251
|
+
tpl = template.Must(template.ParseFiles("view/user/index.html"))
|
252
|
+
|
253
|
+
tpl.Execute(w,Users)
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
出力結果
|
260
|
+
|
261
|
+
```
|
262
|
+
|
263
|
+
2019/07/10 03:23:40.985372 Starting Goji on [::]:8080
|
264
|
+
|
265
|
+
2019/07/10 03:23:44.281110 [ip-172-31-20-61/A9HrA4LsBZ-000001] Started GET "/user/index" from 127.0.0.1:33898
|
266
|
+
|
267
|
+
[]
|
268
|
+
|
269
|
+
2019/07/10 03:23:44.285098 [ip-172-31-20-61/A9HrA4LsBZ-000001] Returning 200 in 3.959931ms
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
エラーの出力はありませんでした。
|
274
|
+
|
275
|
+
|
276
|
+
|
237
277
|
初歩的なことかもしれませんが、よろしくお願いいたします。
|
2
テンプレートファイルの記述・出力結果を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -192,7 +192,29 @@
|
|
192
192
|
|
193
193
|
```
|
194
194
|
|
195
|
-
|
195
|
+
また、テンプレートファイルは以下のように記述しています。
|
196
|
+
|
197
|
+
```Go
|
198
|
+
|
199
|
+
<html>
|
200
|
+
|
201
|
+
<p>user index</p>
|
202
|
+
|
203
|
+
{{range .}}
|
204
|
+
|
205
|
+
<a href="/user/edit/{{.Id}}">{{.Name}}</a><br/>
|
206
|
+
|
207
|
+
{{end}}
|
208
|
+
|
209
|
+
<a href="/user/new">new</a>
|
210
|
+
|
211
|
+
</html>
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
↓テンプレート表示結果です。
|
216
|
+
|
217
|
+
![テンプレート表示結果](de1df0a8da5bb5d5341ecd88e2b12c25.jpeg)
|
196
218
|
|
197
219
|
### 試したこと
|
198
220
|
|
1
"root:@tcp(127.0.0.1:3306)/test"の記述が間違っていたことを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -112,7 +112,7 @@
|
|
112
112
|
|
113
113
|
func init(){
|
114
114
|
|
115
|
-
db, _ = gorm.Open("mysql", "root:@tcp(12
|
115
|
+
db, _ = gorm.Open("mysql", "root:@tcp(127.0.0.1:3306)/test")
|
116
116
|
|
117
117
|
}
|
118
118
|
|