第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

GO:使用 html/template 提供模板時(shí)出錯(cuò)

GO:使用 html/template 提供模板時(shí)出錯(cuò)

Go
素胚勾勒不出你 2021-08-10 15:16:37
我正在使用 html/template 來提供 html,但我不確定我是否正確使用它。我只粘貼了下面的相關(guān)代碼(不完整):這是我的 Go 代碼:func homehandler(w http.ResponseWriter, r *http.Request) {    userName := getUserName(r) //this is defined somewhere    if userName != "" {        t := template.Must(template.New("Tele").Parse(homePage))    t.Execute(w, ReadData()) //ReadData() is a function that reads from the MySQL database and returns a string array    } else {        (...some code)    }}func ReadData() ([]string) {    db, _ := sql.Open("mysql", "user1@/my_db")    (...some code)        rows, err := db.Query("select tweet from posts where username = ?", AddUser.Name) //AddUser is defined somewhere    (...some code)    for rows.Next() {        err := rows.Scan(&tweet)        if err != nil {            fmt.Println(err)        }    v := append(tweetarray, tweet)    fmt.Println(v)    return v    }    return []string{}}Go 代碼中的 html 部分:const homePage = `<html><h1>hi {{ .userName}}</h1><form action="/home/tweets" method="POST"><label for="name">Tweet</label><input type="text" id="tweet" name="twt"</input><button type="Tweet">Tweet</button><h2>{{range $i := .tweetarray}} {{ $i }} {{end}}</h2>`HTML 根本不出現(xiàn)。我在代碼中做錯(cuò)了什么?
查看完整描述

1 回答

?
浮云間

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個(gè)贊

檢查你的錯(cuò)誤!(對(duì)不起,粗體,但這是許多圍棋問題的答案)

t.Execute() 返回錯(cuò)誤,因?yàn)槟哪0逯杏懈袷藉e(cuò)誤的 html。

html/template:Tele: "<" in attribute name: "</input>\n<button type=\"Tweet\">Tw"

在對(duì)此類問題進(jìn)行故障排除時(shí),請(qǐng)嘗試單獨(dú)運(yùn)行每個(gè)部分,或者至少記錄一些調(diào)試信息以進(jìn)行處理。


查看完整回答
反對(duì) 回復(fù) 2021-08-10
  • 1 回答
  • 0 關(guān)注
  • 360 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)