python - Django doesn't recognise keyword blank on child of forms.Form -
i'm trying create form receive empty strings in of values. form not backed model object. i've defined thus:
class searchform(forms.form): device = fields.charfield(blank=true) min_release_date = fields.charfield(blank=true) price_range = fields.charfield(blank=true) has_in_app_purchases = fields.charfield(blank=true)
except when try run test:
def test_valid_no_data(self): webanalytics.web.search import any_price, default_dates, has_iap_ids form_data = { 'price_range': any_price[0], 'min_release_date': default_dates[0], 'has_in_app_purchases': has_iap_ids[0] } search = searchform(form_data) self.asserttrue(search.is_valid())
i following exception:
error: failure: typeerror (__init__() got unexpected keyword argument 'blank') ---------------------------------------------------------------------- traceback (most recent call last): file "/usr/local/lib/python2.7/dist-packages/nose/loader.py", line 411, in loadtestsfromname addr.filename, addr.module) file "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 47, in importfrompath return self.importfromdir(dir_path, fqname) file "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 94, in importfromdir mod = load_module(part_fqname, fh, filename, desc) file "/workspace/aa/tests/ci/unit/webanalytics/web/test_forms.py", line 5, in <module> webanalytics.forms import searchform file "/workspace/aa/webanalytics/forms.py", line 8, in <module> class searchform(forms.form): file "/workspace/aa/webanalytics/forms.py", line 15, in searchform device = fields.charfield(blank=true) file "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py", line 187, in __init__ super(charfield, self).__init__(*args, **kwargs) typeerror: __init__() got unexpected keyword argument 'blank'
according docs should ok. missing something?
this because django form fields don't accept blank
parameter.
the core parameters accepted django form fields are:
- required
- label
- label_suffix
- initial
- widget
- help_text
- error_messages
- validators
localize
you can instead pass
required
parameter valuefalse
. so, if pass empty value – eithernone
or empty string""
, form not raise validation error.
Comments
Post a Comment