2014-04-01 91 views

回答

0

该消息通过翻译实用程序在django.contrib.auth.forms.UserCreationForm中调用(因此您可以在同一身份验证中个性化locale/*/LC_MESSAGES/django.po文件中的翻译文件夹)

您可以覆盖RegistrationForm中的error_messages['duplicate_username']变量,例如

class RegistrationForm(UserCreationForm): 
    def __init__(self, *args, **kwargs): 
     super(RegistrationForm, self).__init__(*args, **kwargs) 
     self.error_messages['duplicate_username'] = 'Your message here' 
+0

谢谢你的回答。但是有什么办法可以在f.ex中覆盖这个消息。我的forms.py文件?我想编辑核心文件不是一个好主意。我的注册表格非常简单:'类RegistrationForm(ModelForm): class Meta: model = User fields =('username','password')' – Eimantas

+0

我已经添加了一个代码覆盖消息的示例 –

+0

对不起我现在正在回答...你的代码工作完美,谢谢你:)应该考虑一下。尽管我仍然是一名学习者。 – Eimantas