model translationissue

11 views
Skip to first unread message

Phil

unread,
Jul 12, 2012, 4:29:00 PM7/12/12
to django...@googlegroups.com
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...


Environment:


Request Method: GET

Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.formtools',
 'django.contrib.admindocs',
 'tagging',
 'blog']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django_mobile.middleware.MobileDetectionMiddleware',
 'django_mobile.middleware.SetFlavourMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/phil/project/urls.py" in <module>
  2. from views import *
File "/home/phil/project/views.py" in <module>
  7. from forms import ContactForm
File "/home/phil/project/forms.py" in <module>
  5. class ContactForm(forms.Form):
File "/home/phil/project/forms.py" in ContactForm
  6.     name = forms.CharField(_('name'), max_length=100)

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


Ian Clelland

unread,
Jul 12, 2012, 8:52:57 PM7/12/12
to django...@googlegroups.com


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
<clel...@gmail.com>
Reply all
Reply to author
Forward
0 new messages