문제

I have declared my signup form (in which user can choose a username and set his email; second step for django-allauth) as follows:

class SignupForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(SignupForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Field('username'),
            Field('email'),
            FormActions(
                Submit('do', u'Reģistrēties', css_class='btn-primary')
            )
        )

        self.fields['username'].label = u'Lietotāja vārds'
        self.fields['email'].label = 'Epasts'

    def save(self, user):
        user.username = self.cleaned_data['username']
        user.email = self.cleaned_data['email']
        user.save()

The problem I'm having - I can override username label but not email. Checking initial email field label yields None.

Is it possible to override EmailField label (and (optional) part of label)? Should I switch to i18n altogether (if in that way I can fully control field labels, error messages etc.)?

도움이 되었습니까?

해결책

Figured it out after I migrated to i18n. You have to extend from BaseSignupForm if you want hardcoded localiziation of field labels and validation error messages. But I'd recommend to stick with built in localization.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top