Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 第二个HTML模板赢得';Golang应用中的t渲染_Javascript_Html_Go_Go Templates - Fatal编程技术网

Javascript 第二个HTML模板赢得';Golang应用中的t渲染

Javascript 第二个HTML模板赢得';Golang应用中的t渲染,javascript,html,go,go-templates,Javascript,Html,Go,Go Templates,在我的应用程序中,login.html模板呈现得很好,但由于某些原因,home.html无法呈现。它只需重新加载login.html。我尝试通过单击登录按钮(该按钮附带了一个将其发送到“/home.html”的操作)访问它,并尝试访问“”,但结果是相同的。有人能给我指一下正确的方向吗 梅因,加油 package main import ( "fmt" "log" "net/http" "text/template" "movieapp/db" ) v

在我的应用程序中,
login.html
模板呈现得很好,但由于某些原因,
home.html
无法呈现。它只需重新加载
login.html
。我尝试通过单击登录按钮(该按钮附带了一个将其发送到“/home.html”的操作)访问它,并尝试访问“”,但结果是相同的。有人能给我指一下正确的方向吗

梅因,加油

package main

import (
    "fmt"
    "log"
    "net/http"
    "text/template"

    "movieapp/db"
)

var loginTmpl, homeTmpl *template.Template

func init() {
    homeTmpl = template.Must(template.ParseFiles("templates/home.html"))
    fmt.Printf("Created template: %v\n", homeTmpl)

    loginTmpl = template.Must(template.ParseFiles("templates/login.html"))
    fmt.Printf("Created template: %v\n", loginTmpl)
}

func main() {
    db.Login()

    fs := http.FileServer(http.Dir("static"))
    http.Handle("/static/", http.StripPrefix("/static/", fs))

    http.HandleFunc("/", loginHandler)
    http.HandleFunc("/home", homeHandler)

    log.Println("listening...")
    http.ListenAndServe(":3000", nil)
}

func loginHandler(w http.ResponseWriter, r *http.Request) {
    if err := loginTmpl.ExecuteTemplate(w, "login", nil); err != nil {
        log.Printf("Failed to execute template: %+v", err)
    }
    fmt.Printf("Request Method: " + r.Method + " Request URL: " + r.URL.EscapedPath() + "\n")
}

func homeHandler(w http.ResponseWriter, r *http.Request) {
    if err := homeTmpl.ExecuteTemplate(w, "home", nil); err != nil {
        log.Printf("Failed to execute template: %+v", err)
    }
    fmt.Printf("Request Method: " + r.Method + " Request URL: " + r.URL.EscapedPath() + "\n")
}
home.html

{{define "home"}}
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Login Successful</title>
    </head>
</html>
{{end}}
{{define“home”}
登录成功
{{end}
login.html

{{define "login"}}
<!DOCTYPE html>
<html lang="en">
<head>
    <title>MovieList</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->  
    <link rel="icon" type="image/png" href="static/images/icons/favicon.ico"/>
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/fonts/Linearicons-Free-v1.0.0/icon-font.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/vendor/animate/animate.css">
<!--===============================================================================================-->  
    <link rel="stylesheet" type="text/css" href="static/vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/vendor/animsition/css/animsition.min.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/vendor/select2/select2.min.css">
<!--===============================================================================================-->  
    <link rel="stylesheet" type="text/css" href="static/vendor/daterangepicker/daterangepicker.css">
<!--===============================================================================================-->
    <link rel="stylesheet" type="text/css" href="static/css/util.css">
    <link rel="stylesheet" type="text/css" href="static/css/main.css">
<!--===============================================================================================-->
</head>
<body>

    <div class="limiter">
        <div class="container-login100">
            <div class="wrap-login100 p-l-85 p-r-85 p-t-55 p-b-55">
                <form class="login100-form validate-form flex-sb flex-w" action="/home.html">
                    <span class="login100-form-title p-b-32">
                        Account Login
                    </span>

                    <span class="txt1 p-b-11">
                        Username
                    </span>
                    <div class="wrap-input100 validate-input m-b-36" data-validate = "Username is required">
                        <input class="input100" type="text" name="username" >
                        <span class="focus-input100"></span>
                    </div>

                    <span class="txt1 p-b-11">
                        Password
                    </span>
                    <div class="wrap-input100 validate-input m-b-12" data-validate = "Password is required">
                        <span class="btn-show-pass">
                            <i class="fa fa-eye"></i>
                        </span>
                        <input class="input100" type="password" name="pass" >
                        <span class="focus-input100"></span>
                    </div>

                    <div class="flex-sb-m w-full p-b-48">
                        <div class="contact100-form-checkbox">
                            <input class="input-checkbox100" id="ckb1" type="checkbox" name="remember-me">
                            <label class="label-checkbox100" for="ckb1">
                                Remember me
                            </label>
                        </div>

                        <div>
                            <a href="#" class="txt3">
                                Forgot Password?
                            </a>
                        </div>
                    </div>

                    <div class="container-login100-form-btn">
                        <button class="login100-form-btn" action="/home.html">
                            Login
                        </button>
                    </div>

                </form>
            </div>
        </div>
    </div>


    <div id="dropDownSelect1"></div>

<!--===============================================================================================-->
    <script src="static/vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
    <script src="static/vendor/animsition/js/animsition.min.js"></script>
<!--===============================================================================================-->
    <script src="static/vendor/bootstrap/js/popper.js"></script>
    <script src="static/vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
    <script src="static/vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
    <script src="static/vendor/daterangepicker/moment.min.js"></script>
    <script src="static/vendor/daterangepicker/daterangepicker.js"></script>
<!--===============================================================================================-->
    <script src="static/vendor/countdowntime/countdowntime.js"></script>
<!--===============================================================================================-->
    <script src="static/js/main.js"></script>

</body>
</html>
{{end}}
{{定义“登录”}
电影演员
帐户登录
用户名
密码
记得我吗
登录
{{end}

您的go代码(修改后可以运行)对我来说运行正常(操场上的代码——请注意,您不能在操场上运行)。“登录”按钮不起作用(我认为这是HTML的问题),但直接导航到“登录”按钮。看起来在IDE重新启动后,代码开始工作了!哈哈,谢谢你的帮助。