小编yet*_*lue的帖子

Djoser 使用模板覆盖激活电子邮件

我一直在寻找有关如何执行此操作的更多信息,但似乎几乎没有文档帮助。

本质上我想要做的是为激活电子邮件创建一个新模板,以便链接可以以 localhost:3000 而不是 localhost:8000 开头(我使用 Vue 作为前端发布请求,这就是为什么)

我设法找到了这个:https : //github.com/sunscrapers/djoser/blob/master/djoser/templates/email/activation.html 但是当我将它添加到我自己的项目时,仍然使用默认的 Djoser 模板。

这是我的 settings.py 的样子:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
Run Code Online (Sandbox Code Playgroud)

如果手动将 8000 替换为 3000,我的激活 URL 有效:

 'ACTIVATION_URL': 'registration/activate/{uid}/{token}',
Run Code Online (Sandbox Code Playgroud)

模板/电子邮件/activation.html:

{% block subject %}
{% blocktrans %}Account activation on {{ site_name }}{% endblocktrans %}
{% endblock subject %}

{% block text_body %}
{% blocktrans %}You're receiving this …
Run Code Online (Sandbox Code Playgroud)

django-templates python-3.x django-rest-framework djoser

4
推荐指数
1
解决办法
1880
查看次数