亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

制作一個基于Python的網站,具有電子郵件收集功能,但輸入電子郵件時崩潰

制作一個基于Python的網站,具有電子郵件收集功能,但輸入電子郵件時崩潰

偶然的你 2023-07-27 17:57:25
我為一個鷹項目制作了一個網站,其中一部分人們可以提交電子郵件,以便我稍后可以聯系他們。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():可以控制你的表單。


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號