Flask 错误在服务器自定义表单系统上未找到 URL
嘿,我在烧瓶中制作一个程序,让用户填写表格,然后将该表格通过电子邮件发送到特定的电子邮件。以前工作得很好,但由于某种原因现在不行了。这是我的代码:
@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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我找到了答案。因此,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.