嘿,我在燒瓶中制作了一個程式,讓用戶填寫表格,然后它將該表格通過電子郵件發送到特定的電子郵件。它以前作業得很好,但由于某種原因現在不是。這是我的代碼:
@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 模板
<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>
我沒有收到任何錯誤,它說的是在服務器上找不到請求的 url
uj5u.com熱心網友回復:
所以我找到了答案。因此,flask 不允許將https://github.com/codingdudepy等特定鏈接作為重定向 url 回傳。由于某種原因,它也不允許像 # 這樣的東西或像 .com 這樣的域。當我洗掉這些東西時,它作業得很好。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/447389.html
上一篇:將音頻與文本匹配
下一篇:在WP中編輯索引檔案
