我用模板标签做到了:
https ://docs.djangoproject.com/fr/1.10/howto/custom-template-tags/
我的模板标签文件(例如settings_vars.py
):
from django import template
from django.conf import settings
register = template.Library()
@register.simple_tag
def get_settings_var(name):
return getattr(settings, name)
我的变量settings.py
:
FRONTEND_URL = 'http://localhost:4200/'
ACCOUNT_EMAIL_CONFIRMATION_URL = FRONTEND_URL + 'verify-email/{}'
ACCOUNT_PASSWORD_RESET_CONFIRM = FRONTEND_URL + 'password-reset/confirm/'
我的用法password_reset_email.html
:
{% load settings_vars %}
{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{% get_settings_var 'ACCOUNT_PASSWORD_RESET_CONFIRM' %}?uidb64={{ uid }}&token={{ token }}
{% endblock %}
如果有人知道更好的解决方案,请随时发表评论。
希望它可以帮助某人。