制作一个基于Python的网站,具有电子邮件收集功能,但输入电子邮件时崩溃

我为一个鹰项目制作了一个网站,其中一部分人们可以提交电子邮件,以便我稍后可以联系他们。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,request


app = 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。如果您手动输入网址,请检查拼写并重试 有人可以帮忙吗


偶然的你
浏览 92回答 1
1回答

慕运维8079593

您的表格有问题:你有:<form&nbsp;action="contact"&nbsp;method="post">并且应该是<form&nbsp;action="{{url_for('signup')}}"&nbsp;method="POST">请注意,{{url_for('signup')}}我在里面写的'signup'是因为在你的Python代码中def signup():可以控制你的表单。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python