Flask 错误在服务器自定义表单系统上未找到 URL

发布于 2025-01-15 06:08:16 字数 2614 浏览 1 评论 0原文

嘿,我在烧瓶中制作一个程序,让用户填写表格,然后将该表格通过电子邮件发送到特定的电子邮件。以前工作得很好,但由于某种原因现在不行了。这是我的代码:

@app.route('/application', methods=['POST', 'GET'])
def application():
    if request.method == 'POST':
        name = request.form["name"]
        github = request.form["github"]
        age = request.form["age"]
        location = request.form["location"]
        email = request.form["email"]
        discord = request.form["discord"]

        return redirect(f"/final/{name}/{github}/{age}/{location}/{email}/{discord}/")

@app.route('/final/<name>/<github>/<age>/<location>/<email>/<discord>/', methods=['GET','POST'])
def final(name, github, age, location, email, discord):
    mail= Mail(app)

    app.config['MAIL_SERVER']='smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USERNAME'] = '[email protected]'
    app.config['MAIL_PASSWORD'] = '*******'
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True
    b = Markup(f"Name: {name}\r\nGithub: {github}\r\nAge: {age}\r\nlocation: {location}\r\nemail: {email}\r\ndiscord: {discord}")
    msg = Message(f'Application {name}', sender = '[email protected]', recipients = [email])
    msg.body = b
    mail.send(msg)
    return render_template("final.html" )

HTML TEMPLATE

  <form action="/application" method="POST">
            <p><input type = "text" name="name" placeholder="First And Last Name" /></p>
            <br><br>
            <p><input type = "text" name="github" placeholder="GitHub Profile Link" /></p>
            <br><br>
            <p><input type = "text" name="age" placeholder="Age" /></p>
            <br><br>
            <p><input type = "text" name="location" placeholder="State/Country" /></p>
            <br><br>
            <p><input type = "text" name="email" placeholder="Email" /></p>
            <br><br>
            <p><input type = "text"  name="discord" placeholder="Discord username and tag(if you have one)" /></p>
            <p><input type="submit"  value="Submit" /></p>
        </form>

我没有收到任何错误,它说的是在服务器上找不到请求的网址

Hey im making a program in flask that lets users fill out a form and then it will email that form to a specific email. It was working perfectly fine before but for some reason now it is not. Here is my code:

@app.route('/application', methods=['POST', 'GET'])
def application():
    if request.method == 'POST':
        name = request.form["name"]
        github = request.form["github"]
        age = request.form["age"]
        location = request.form["location"]
        email = request.form["email"]
        discord = request.form["discord"]

        return redirect(f"/final/{name}/{github}/{age}/{location}/{email}/{discord}/")

@app.route('/final/<name>/<github>/<age>/<location>/<email>/<discord>/', methods=['GET','POST'])
def final(name, github, age, location, email, discord):
    mail= Mail(app)

    app.config['MAIL_SERVER']='smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USERNAME'] = '[email protected]'
    app.config['MAIL_PASSWORD'] = '*******'
    app.config['MAIL_USE_TLS'] = False
    app.config['MAIL_USE_SSL'] = True
    b = Markup(f"Name: {name}\r\nGithub: {github}\r\nAge: {age}\r\nlocation: {location}\r\nemail: {email}\r\ndiscord: {discord}")
    msg = Message(f'Application {name}', sender = '[email protected]', recipients = [email])
    msg.body = b
    mail.send(msg)
    return render_template("final.html" )

HTML TEMPLATE

  <form action="/application" method="POST">
            <p><input type = "text" name="name" placeholder="First And Last Name" /></p>
            <br><br>
            <p><input type = "text" name="github" placeholder="GitHub Profile Link" /></p>
            <br><br>
            <p><input type = "text" name="age" placeholder="Age" /></p>
            <br><br>
            <p><input type = "text" name="location" placeholder="State/Country" /></p>
            <br><br>
            <p><input type = "text" name="email" placeholder="Email" /></p>
            <br><br>
            <p><input type = "text"  name="discord" placeholder="Discord username and tag(if you have one)" /></p>
            <p><input type="submit"  value="Submit" /></p>
        </form>

I get no errors all it says is that the the requested url wasnt found on the server

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裂开嘴轻声笑有多痛 2025-01-22 06:08:16

所以我找到了答案。因此,Flask 不允许诸如 https://github.com/codingdudepy 作为重定向网址返回的特定链接。由于某种原因,它也不允许使用 # 或 .com 等域名。当我删除这些东西时,它工作得很好。

So i found an answer. So flask doesnt allow specifc links such as https://github.com/codingdudepy to be returned as a redirect url. Nor does it allow things like #, or domains like .com for some reason. When i removed these things it worked perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文