1

I have wriiten some code here. Please check out the file. When I filled all the fields from django admin then it's working but when I redirect it with http://127.0.0.1:8000/user/application then I am getting below error

return [
TypeError: 'User' object is not iterable

Traceback

Traceback (most recent call last):
  File "C:\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Python\Python38\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\Python\Python38\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\views.py", line 476, in raise_uncaught_exception
    raise exc
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\generics.py", line 239, in get
    return self.list(request, *args, **kwargs)
  File "E:\Project\twitapp\twitapp-core\user\views.py", line 142, in list
    return self.get_paginated_response(serializer.data)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 757, in data
    ret = super().data
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 261, in data
    self._data = self.to_representation(self.instance)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 674, in to_representation
    return [
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 675, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "E:\Project\twitapp\twitapp-core\user\serializers.py", line 274, in to_representation
    data = super(ApplicationFormSerializer, self).to_representation(instance)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 526, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "C:\Users\Public\AppData\Roaming\Python\Python38\site-packages\rest_framework\serializers.py", line 674, in to_representation
    return [
TypeError: 'User' object is not iterable
2021-04-25 11:32:10,608 django.server ERROR    "GET /user/application/ HTTP/1.1" 500 27

Where I did wrong? How can I solve it? What is the mean of this?

7
  • 3
    There should be more to your error message (Traceback), It can help find out where the problem takes place. If you have that please add it to your code block here on stack as it can help people assist you easier. Commented Apr 25, 2021 at 6:31
  • @Lemon.py I have added my traceback Commented Apr 25, 2021 at 6:41
  • "E:\Project\twitapp\twitapp-core\user\views.py", line 142, in list Can you share this view, related serializer and model? @Kwall Commented Apr 25, 2021 at 7:43
  • @KutayAslan I have provide all the code in the link you can see the line number 32 to 41 in views.py file. this is the which is given in traceback Commented Apr 25, 2021 at 7:49
  • @Kwall edit your question and add the code there. Plus the link you provide to show your code does not show your code (it is not even meant to, it is just an online interpreter for python not a code storing service or so). Commented Apr 25, 2021 at 8:12

1 Answer 1

1

according to the type of error, use passes an object that has no __iter__ specific attribute, while the objects you should pass are something like list, set and etc.

Sign up to request clarification or add additional context in comments.

1 Comment

inside the views?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.