Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: "Object is not iterable", when trying to modify said object
    text
    copied!<p>I am trying to edit an object ("Worry") which has been already created.</p> <p>I have this code in views.py:</p> <pre><code>def worry_edit(request, id): worry = get_object_or_404(Worry, pk = id) original_pub_date = worry.pub_date form = WorryForm(request.POST or None, instance = worry) if form.is_valid(): worry = form.save(commit = False) worry.pub_date = original_pub_date worry.save() return redirect(worry) return render_to_response('holaProy/worry_edit.html', {'worry_form': form, 'worry_id': id}, context_instance=RequestContext(request)) </code></pre> <p>Which gives the following error when hitting the send button on the form:</p> <pre><code>argument of type 'Worry' is not iterable </code></pre> <p>Any insights on why that error is appearing and how to solve it?</p> <p>Edit: As suggested by Girasquid, this is the complete traceback:</p> <pre><code>Environment: Request Method: POST Request URL: http://127.0.0.1:8000/holaProy/worry_edit/1/ Django Version: 1.4.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.admindocs', 'holaProy', 'registration', 'django.contrib.humanize') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "C:\Users\Richard\proyectosPython\holaProyecto\holaProyecto\holaProy\views.py" in worry_edit 50. return redirect(worry) File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in redirect 81. if '/' not in to and '.' not in to: Exception Type: TypeError at /holaProy/worry_edit/1/ Exception Value: argument of type 'Worry' is not iterable </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload