[Django]-Django customizing form labels

2👍

You should change the form init decleration, that QueryDict tha gets printed is the request.GET or request.POST that you pass as first argument when you initialize the form.

i guess changing this

def __init__(self, subject_label="Subject", ...

to this

def __init__(self, data=None, subject_label="Subject", ... ...):
    super(ContactForm, self).__init__(data, *args, **kwargs)
    ...

will solve your problem.

2👍

I think you’re approaching the problem the wrong way. You should use the internationalisatoin module instead.

That way you can have your form like this:

class ContactForm(forms.Form):
    subject = forms.CharField(label=_('contact_form_subject'), widget=forms.TextInput(attrs={'size':'60'}))

The Django internationalisation system will automatically insert the correct translation for you if you provide the translation files.

👤Wolph

Leave a comment