Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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 {{domain}}在本地pc上成为example.com_Python_Django - Fatal编程技术网

Python {{domain}}在本地pc上成为example.com

Python {{domain}}在本地pc上成为example.com,python,django,Python,Django,我正在学习用django发送邮件,但我进入了这个问题,它返回http://example.com/而不是http://127.0.0.1:8000/ 发送邮件并生成链接的代码如下(我在两行上添加了注释,我怀疑这是原因): 我将如何更正这一点,因为函数应该使用该域。理想情况下,我可以在部署应用程序时在settings.py中定义它 先谢谢你 编辑!添加了电子邮件模板我认为您已经配置了django框架。因此,不要使用request.get\u host() 或者您可以将您的站点域从django管理面

我正在学习用django发送邮件,但我进入了这个问题,它返回
http://example.com/
而不是
http://127.0.0.1:8000/

发送邮件并生成链接的代码如下(我在两行上添加了注释,我怀疑这是原因):

我将如何更正这一点,因为函数应该使用该域。理想情况下,我可以在部署应用程序时在
settings.py
中定义它

先谢谢你


编辑!添加了电子邮件模板

我认为您已经配置了django框架。因此,不要使用
request.get\u host()


或者您可以将您的站点域从django管理面板更改为
127.0.0.1
example.com
get\u current\u站点(请求)。域将工作

开始!我不知道。非常感谢你!
views.py
# Send activation E-mail
        current_site = get_current_site(self.request)  # Either this line
        mail_subject = 'Activate your Penge account.'
        message = render_to_string('emails/activation-mail.html', {
            'user': user,
            'domain': current_site.domain,  # or maybe this line
            'uid': urlsafe_base64_encode(force_bytes(user.pk)),
            'token': default_token_generator.make_token(user),
        })
        to_email = form.cleaned_data.get('email')
        email = EmailMessage(
            mail_subject, message, to=[to_email]
        )
        email.send()
        return HttpResponse('Please confirm your email address')
activation-mail.html

{% autoescape off %}
Hi {{ user.username }},

Please click on the link to confirm your registration,
http://{{ domain }}{% url 'accounts:activate' uidb64=uid token=token %}

If you think, it's not you, then please ignore this email.
{% endautoescape %}
'domain': request.get_host(),