我在django应用程序中使用了allauth。创建用户后,它会发送一封包含此http://localhost:8001/account/confirm-email/asdfafsd/
但是,我希望链接为http://localhost:8001/verifyEmail/asdfafsd
,因为我在前端使用了角度。
我无法找出更改此链接的位置?
答案 0 :(得分:1)
templates/account/email_confirmation_message.txt
创建示例自定义标签,并将其包含在您的任何应用中,即
例如userprofile
userprofile/templatetags/userprofile.py
userprofile.py
代码中的可以像
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.simple_tag(name="make_confirm_url", takes_context=True)
def make_confirm_url(context):
activate_url = context.get('activate_url')
slice_idx = activate_url.find('account')
return ''.join(['http://', context.get('current_site').domain, '/',activate_url[slice_idx:]])
email_confirmation_message.txt
就像
{% load userprofile %}{% make_confirm_url as the_link %}
{% load account %}{% user_display user as user_display %}{% load i18n %}
{% autoescape off %}{% blocktrans with site_name=current_site.namesite_domain=current_site.domain %}
Hello from {{ site_name }}!
You're receiving this e-mail because user {{ user_display }} has given yours as an e-mail address to connect their account.
To confirm this is correct, go to {{the_link}}
{% endblocktrans %}{% endautoescape %}
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }} Dev Team !
{{ site_domain }}{% endblocktrans %}
在上面的代码中,域是从django_sites模型中获取的。您可以包括逻辑,并在前端框架(例如angular)中相应地编写路由。谢谢
答案 1 :(得分:0)
添加到urls.py自定义网址:
url(r"^verifyEmail/(?P<key>\w+)/$", allauth.accounts.views.confirm_email, name="my_confirm_email")
编辑电子邮件模板以使用&#39; my_confirm_email&#39;网址:
http://django-allauth.readthedocs.org/en/latest/advanced.html#sending-e-mail