Reputation: 452
I use Django version 1.8. I have a very simple form which I show below. It contains only a single field, a DecimalField
. When I try to render any template in my whole project, I get
TypeError at /whatever/
__init__() got an unexpected keyword argument 'max_decimal_places'
Here's my complete forms.py
file:
from django import forms
class BidForm(forms.Form):
amount = forms.DecimalField(label="Bid amount", max_decimal_places=2)
If I delete the max_decimal_places=2
kwarg that the error message seems to be whining about, my site renders fine and everything works great.
Why can't I seem to utilize max_decimal_places
?
Complete stack trace follows.
Environment:
Request Method: GET
Request URL: http://myproject.username.webfactional.com/myapp/
Django Version: 1.8.4
Python Version: 3.4.1
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.staticfiles',
'localflavor',
'myapp')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/core/handlers/base.py" in get_response
119. resolver_match = resolver.resolve(request.path_info)
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/core/urlresolvers.py" in resolve
366. for pattern in self.url_patterns:
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/core/urlresolvers.py" in url_patterns
402. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/core/urlresolvers.py" in urlconf_module
396. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python3.4/importlib/__init__.py" in import_module
109. return _bootstrap._gcd_import(name[level:], package, level)
File "/home/username/webapps/myapplication/myproject/myproject/urls.py" in <module>
8. url(r'^myapp/', include('myapp.urls', namespace='myapp')),
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/conf/urls/__init__.py" in include
33. urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python3.4/importlib/__init__.py" in import_module
109. return _bootstrap._gcd_import(name[level:], package, level)
File "/home/username/webapps/myapplication/myproject/myapp/urls.py" in <module>
2. from . import views
File "/home/username/webapps/myapplication/myproject/myapp/views.py" in <module>
3. from .forms import BidForm
File "/home/username/webapps/myapplication/myproject/myapp/forms.py" in <module>
3. class BidForm(forms.Form):
File "/home/username/webapps/myapplication/myproject/myapp/forms.py" in BidForm
11. amount = forms.DecimalField(label="Bid amount", max_decimal_places=2)
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/forms/fields.py" in __init__
334. super(DecimalField, self).__init__(max_value, min_value, *args, **kwargs)
File "/home/username/webapps/myapplication/lib/python3.4/Django-1.8.4-py3.4.egg/django/forms/fields.py" in __init__
245. super(IntegerField, self).__init__(*args, **kwargs)
Exception Type: TypeError at /myapp/
Exception Value: __init__() got an unexpected keyword argument 'max_decimal_places'
Upvotes: 1
Views: 542
Reputation: 2569
See the docs about the DecimalField
You can use decimal_places
:
The maximum number of decimal places permitted.
Upvotes: 3