我為一個鷹項目制作了一個網站,其中一部分人們可以提交電子郵件,以便我稍后可以聯系他們。html 看起來像這樣:{%extends "layout.html"%}{%block content%}<div class= "contact"> <h1>How can you help?</h1> <br> <p> The biggest way to help is to <strong>DONATE</strong> to the Eagle project. Another way that you can help is to volunteer on a work day. This counts for volunteer hours. </p> <br> <h2>Donations</h2> <p>you can donate in the following ways</p> <ul> <li><a href="">CashApp</a></li> <li><a href="">Venmo</a></li> <li>Or a check made out to <strong>lorem</strong></li> </ul> <h2>Volunteer</h2> <p>If you would like to volunteer enter your email below and I will contact you</p> <form action="contact" method="post"> <input type="text" name="email" placeholder = "enter email here"> <input type="submit" value="Submit"> </form> <h2>Contact Me</h2> <ul> <li>My email:lorem</li> <li>My number: lorem</li> </ul></div>{%endblock%}python 后端如下所示:from flask import Flask, render_template,redirect,requestapp = Flask(__name__)@app.route("/contact/", methods = ["POST"])def signup(): file=open("email_list", "a") email = request.form["email"] file.write(email+"\n") file.close() return redirect("/")@app.route("/")def home(): return render_template("home.html")@app.route("/about/")def about(): return render_template("about.html")@app.route("/contact/")def contact(): return render_template("contact.html")if __name__ == "__main__": app.run(debug=True)每當我輸入電子郵件時,我都會收到: 在服務器上找不到請求的 URL。如果您手動輸入網址,請檢查拼寫并重試 有人可以幫忙嗎
1 回答

慕運維8079593
TA貢獻1876條經驗 獲得超5個贊
您的表格有問題:
你有:
<form action="contact" method="post">
并且應該是
<form action="{{url_for('signup')}}" method="POST">
請注意,{{url_for('signup')}}
我在里面寫的'signup'
是因為在你的Python代碼中def signup():
可以控制你的表單。
添加回答
舉報
0/150
提交
取消