'Problem with generating a link to change the user's password
For educational purposes, I am developing a web application, at the moment I am trying to implement a password reset function through a link sent to email. I generate a link using url_for and ran into a problem that it creates a link by inserting 'localhost' instead of the github server on which I run the application (not sure that I described the problem right). the question is how do I replace this 'localhost' with the data I need, thanks for advance
db_user = db.execute("SELECT * FROM users WHERE email = (?)", email)
token = get_reset_password_token(db_user[0]['ID'])
message = Message("хххх", recipients=[email])
url = url_for('reset_password', token=token, _external=True)
message.body = render_template("/reset_password.txt", url=url)
mail.send(message)
flash("ххх")
return render_template("login.html")
else:
return render_template("сhange_password.html")
@app.route('/reset_password/<token>', methods=['GET', 'POST'])
def reset_password(token):
if request.method == "POST":
id = verify_reset_password_token(token)
if not id:
return redirect("/")
Link from email: http://localhost/reset_password/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXNldF9wYXNzd29yZCI6MSwiZXhwIjoxNjUyMDAwODczLjUwMzQ5NDV9.g178uD02_3o65_f...
Solution 1:[1]
Per the documentation
_external – if set to True, an absolute URL is generated. Server address can be changed via SERVER_NAME configuration variable which falls back to the Host header, then to the IP and port of the request.
So, if you run the App from your local machine (localhost), it will pick that value. If you run it from somewhere on the web, it will pick the host for that web server. You can set a specific value via SERVER_NAME
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | NoCommandLine |
