Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Django 如何更改allauth中的电子邮件验证链接_Django_Angularjs - Fatal编程技术网

Django 如何更改allauth中的电子邮件验证链接

Django 如何更改allauth中的电子邮件验证链接,django,angularjs,Django,Angularjs,我在django应用程序中使用allauth。一旦用户被创建,它就会发送一封带有如下链接的电子邮件http://localhost:8001/account/confirm-电子邮件/asdfafsd/ 但是,我希望链接是http://localhost:8001/verifyEmail/asdfafsd因为我在前端使用了angular 我不知道在哪里更改此链接?添加到URL.py自定义URL: url(r“^verifyEmail/(?p\w+)/$”,allauth.accounts.vie

我在django应用程序中使用allauth。一旦用户被创建,它就会发送一封带有如下链接的电子邮件
http://localhost:8001/account/confirm-电子邮件/asdfafsd/

但是,我希望链接是
http://localhost:8001/verifyEmail/asdfafsd
因为我在前端使用了angular


我不知道在哪里更改此链接?

添加到URL.py自定义URL:

url(r“^verifyEmail/(?p\w+)/$”,allauth.accounts.views.confirm\u email,name=“my\u confirm\u email”)

并编辑电子邮件模板以使用“我的确认电子邮件”url:

  • 通过创建相同的命名文件来替代模板。 对于django allauth:
    templates/account/email\u confirmation\u message.txt
  • 创建一个示例自定义标记并包含在您的任何应用程序中,即 例如
    userprofile/templatetags/userprofile.py中的app
    userprofile

  • 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:]])
    
    {% 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 %}
    
  • email\u confirmation\u message.txt
    可以是

    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:]])
    
    {% 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_站点模型获取的,您可以包含逻辑并在前端框架中相应地编写路由(如angular)。谢谢


  • 如何编辑电子邮件模板?我在代码中的任何地方都找不到文件
    account/email/email\u confirmation\u message.txt
    。这似乎不是我想要的。
    verifyEmail
    URL已经在我的angular应用程序中生成,并且工作得非常好。我只想将发送给用户的电子邮件中的URL更改为相同的
    verifyEmail
    URL,而不是
    http://localhost:8001/account/confirm-email/asdfafsd/
    这是我正在尝试更改的URL您说您想更改所有的电子邮件验证URL,但链接到github会导致django的用户密码重置电子邮件模板。您所需要做的就是在服务器端创建url。您只能通过angularjs在客户端完成。若要更改电子邮件中的url,您应该创建自定义电子邮件模板,该模板将覆盖来自allauth的标准模板。为此,您需要将模板目录从allauth复制到项目的模板目录,并编辑模板以进行电子邮件验证。