简体   繁体   中英

Django signup view: TypeError: 'set' object is not subscriptable

My web application on django catch an error due signup with different passwords typed. All other form errors works fine include taken email, empty fields and so. Error comes in at validating signup form.

Don't really understand why i have this error, because it not affected by my code (i guess).

Here is traceback:

Traceback (most recent call last):
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/kotofey/AccentAcademy/registration/views.py", line 44, in signup
    if form.is_valid():
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/forms/forms.py", line 185, in is_valid
    return self.is_bound and not self.errors
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/forms/forms.py", line 180, in errors
    self.full_clean()
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/forms/forms.py", line 381, in full_clean
    self._clean_fields()
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/forms/forms.py", line 402, in _clean_fields
    value = getattr(self, 'clean_%s' % name)()
  File "/home/kotofey/AccentAcademy/aaenv/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 101, in clean_password2
    self.error_messages['password_mismatch'],
TypeError: 'set' object is not subscriptable

It looks like whatever form you're rendering on line 44 has an error_messages property which is of type set , instead of some subscriptable type (like dict ).

It follows that you've defined a form with an error_messages property of the wrong type.

If you examine the code for that form instance (wherever it is defined), chances are you'll find the "bad" error_messages property.

You could also try loading the form and examining it a bit:

$./manage.py shell
>>>> from some.app.forms import SomeFormClass
>>>> f = SomeFormClass()
>>>> type(f.error_messages)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM