5

我想在这个 ValidationError 中添加一个锚标记:

Customer.objects.get(email=value)
            if self.register:
                # this address is already registered
                raise forms.ValidationError(
                    _('An account already exists for this email address')
                )

锚标记将是<a href="some/url/to/login">Log in instead</a>

因此,当用户输入已经存在的电子邮件时,错误消息将类似于:

'此电子邮件地址的帐户已存在。而是<a>登录</a>

提前致谢!

4

1 回答 1

10

这有效:

Customer.objects.get(email=value)
    if self.register:
    # this address is already registered
    raise forms.ValidationError(
    (_(mark_safe('An account already exists for this email address. <a href="#" class="email_error">Log in instead?</a>')))
 )

...但在 Python 文件的顶部也需要这个:

from django.utils.safestring import mark_safe
于 2013-09-13T13:59:55.527 回答