为了账号安全,请及时绑定邮箱和手机立即绑定

制作一个基于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 关注
  • 50 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信