Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在电子邮件中,_external=True意味着什么?_Python_Web_Flask_Project_Flask Mail - Fatal编程技术网

Python 在电子邮件中,_external=True意味着什么?

Python 在电子邮件中,_external=True意味着什么?,python,web,flask,project,flask-mail,Python,Web,Flask,Project,Flask Mail,我正在制作一个Flask应用程序,学习如何使用Flask_邮件模块发送重置电子邮件,因此我想知道当我将重置链接放在邮件正文上时,_external=True(发送重置电子邮件功能)是什么意思。我在谷歌上搜索过,但什么也没找到。提前谢谢。\u external=True告诉Flask它应该生成一个绝对URL,而不是一个相对URL。例如,https://example.com/my-page是一个绝对URL,但/my page是一个相对URL。由于您正在发送电子邮件,因此指向站点中某个页面的相对UR

我正在制作一个Flask应用程序,学习如何使用Flask_邮件模块发送重置电子邮件,因此我想知道当我将重置链接放在邮件正文上时,_external=True(发送重置电子邮件功能)是什么意思。我在谷歌上搜索过,但什么也没找到。提前谢谢。

\u external=True
告诉Flask它应该生成一个绝对URL,而不是一个相对URL。例如,
https://example.com/my-page
是一个绝对URL,但
/my page
是一个相对URL。由于您正在发送电子邮件,因此指向站点中某个页面的相对URL将不起作用

您可以在此处查看的
url\u文档:

_外部–如果设置为True,则生成绝对URL。可以通过服务器名称配置变量更改服务器地址,该变量 返回到主机头,然后返回到请求的IP和端口


谢谢你的帮助,这正是我所需要的!
import os
import secrets
from PIL import Image
from flask import url_for, current_app
from flask_mail import Message
from app import mail


def save_picture(form_picture):
    random_hex = secrets.token_hex(8)
    f_name, f_ext = os.path.splitext(form_picture.filename)
    picture_fn = random_hex + f_ext
    picture_path = os.path.join(current_app.root_path, 'static/profile_pics', picture_fn)
    output_size = (125, 125)
    i = Image.open(form_picture)
    i.thumbnail(output_size)
    i.save(picture_path)
    return picture_fn

def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request', sender='noreplies@diemo.hr', recipients=[user.email])
    msg.body = f''' To reset your password, visit the following link:
{url_for('users.reset_token', token=token, **_external=True**)}
If you did not make this request then simply ignore this email and no changes will be made
    '''
    mail.send(msg)