我想以我的母语显示错误消息。 下面粘贴了4个不同试验的代码,但都没有 我找到的所有方法都不起作用 Django, Models & Forms: replace "This field is required" message
forms.py
class UserCreateForm(UserCreationForm):
email = forms.EmailField(required=True, error_messages = {'required': "custom"})
first_name = forms.CharField(required=True)
last_name = forms.CharField(required=True)
class Meta:
model = User
fields = ("username", "email", "password1", "password2", "first_name", "last_name")
error_messages = {
'unique_together': "custom",
'blank': "custom",
'null': "custom",
}
def __init__(self, *args, **kwargs):
super(UserCreateForm, self).__init__(*args, **kwargs)
self.fields['email'].error_messages = {'required': 'custom'}
# if you want to do it to all of them
for field in self.fields.values():
field.error_messages = {'required':'custom {fieldname} custom'.format(
fieldname=field.label)}
views.py
def signup(request, string, step):
if request.POST:
user_form = UserCreateForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
Profile.objects.create(**{
'city':request.POST['city'], 'phone': request.POST['phone'], 'isStudent': istudent, 'emailnotafications': request.POST.get('emailnotafications', False), 'user': user
})
...
模板
<div class="form-group field-user-username required">
<label class="control-label" for="user-username">Email</label>
{{ user_form.email |add_class:"form-control" }}
</div>
<div class="form-group field-user-username required">
<label class="control-label" for="user-username">Hasło</label>
{{ user_form.password1 |add_class:"form-control" }}
</div>
答案 0 :(得分:0)
您可以尝试通过向窗口小部件添加属性来禁用:
declare @paymentID as int
set @paymentID = SP_generatePaymentID '2014-03-01','Benzir Pinjari'
select @paymentID