Thursday, July 12, 2012

Re: model translationissue



On Thursday, July 12, 2012, Phil wrote:
Hi,

I'm trying to translate form names from a model. I have a working contact form for example and have the following code....

============================

from django import forms
from django.core.mail import mail_managers
from django.utils.translation import ugettext_lazy as _

class ContactForm(forms.Form):
    name = forms.CharField(_('name'), max_length=100)


==========================

It adds it to my .po file ok, but when I run it in the browser I get the following error...


Exception Type: TypeError at /contact/
Exception Value: __init__() got multiple values for keyword argument 'max_length'



max_length is the first argument to the CharField constructor. You provided it twice (accidentally, I'm sure): once as the first argument, and again as a named parameter.

If the argument "_('name')" is supposed to be the field label, then you should pass it explicitly as that keyword art, like this:

    name = forms.CharField(label=_('name'), max_length=100)

Ian


--
Regards,
Ian Clelland
<clelland@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate