• Register
0 votes

Problem :

I have below error message on the django 1.4:

“Dictionary update sequence element #0 has length 1; 2 is required”

It happened to me when I tried using a template tag like: `{% for v in values %}

It happens too when I try to access on the hstore queryset

My code is as below:

mytmp = Item.objects.where(HE("kv").contains({'key':value}))
if mytmp.count() > 0:
item_id = mytmp[0].id,

I am just trying to access a value. I don't understand a "update sequence" message. When I use the cursor instead of the hstore queryset, a function works. A error comes on template rendering too. I just restarted the uwsgi and everything works well, but above error comes back later.

Has someone an idea to fix this error?

7 5 2
3,870 points

2 Answers

0 votes

Solution :

Just ran into your problem. The root cause was because I just forgot to put the name= on a last argument of a url (or a path in Django 2.0+) function call.

For example, the below functions throw a error from your question:

url(r'^foo/(?P<bar>[A-Za-z]+)/$', views.FooBar.as_view(), 'foo')

path('foo/{slug:bar}/', views.FooBar, 'foo')

But below one actually work:

url(r'^foo/(?P<bar>[A-Za-z]+)/$', views.FooBar.as_view(), name='foo')

path('foo/{slug:bar}/', views.FooBar, name='foo')

So a reason why a traceback is unhelpful is as internally, Django wants to parse a given positional argument as a keyword argument kwargs, and since the string is the iterable, the atypical code path begins to unfold. So always use a name= on your urls!

9 7 4
38,600 points
0 votes


Just ran into this problem. I don't know if it's the same thing that hit your code, but for me the root cause was because I forgot to put name= on the last argument of the url (or path in Django 2.0+) function call.

the following functions throw the error from the question:

url(r'^foo/(?P<bar>[A-Za-z]+)/$', views.FooBar.as_view(), 'foo')
path('foo/{slug:bar}/', views.FooBar, 'foo')

However it will work,

url(r'^foo/(?P<bar>[A-Za-z]+)/$', views.FooBar.as_view(), name='foo')
path('foo/{slug:bar}/', views.FooBar, name='foo')

The reason why the traceback is unhelpful is because internally, Django wants to parse the given positional argument as the keyword argument kwargs, and since a string is an iterable, an atypical code path begins to unfold. Always use name= on your urls!

 get dict from string is:

dic2 = eval(str1)
{'taras': 'vaskiv', 'iruna': 'vaskiv'}

Or in matter of security we can use literal_eval

from ast import literal_eval

pass a keyword argument name to url() function

url(r"^testing/$", views.testing, name="testing")


Another way of solve this issue

Pass a keyword argument name with value as your view name e.g home or home-view etc. to url() function.


Throws Error:

url(r'^home$', 'common.views.view1', 'home'),


url(r'^home$', 'common.views.view1', name='home'),

You are sending one parameter incorrectly; it should be a dictionary object:

Wrong: func(a=r)

Correct: func(a={'x':y})

I got the same issue and found that it was due to wrong parameters. In views.py, I used:

return render(request, 'demo.html',{'items', items})  

However, I found the issue: {'items', items}. Changing to {'items': items} resolved the issue.

10 6 4
31,120 points

Related questions

1 vote
1 answer 335 views
Problem : I am very new to Django. My current task is to store the form field variable with the help of Django cache and I have already added the Django form in my view. I am often facing below error and as I am very new to Django so unable to understand the below ...         form = Formulary() return render(request, 'form.html', {'form' : form}) I am looking for Django expert to fix above error.
asked May 1 stewart 4k points
0 votes
0 answers 6 views
I am doing the crash course in python book , and have checked the code multiple times getting the same error, can anyone help me with this, this is my code: view.py from django.shortcuts import render from django.http import HttpResponseRedirect from django.urls ... ', views.new_topic, name='new_topic'),     # adding entries     path('new_entry/<topic_id>/', views.new_entry, name='new_entry'), ]
asked Sep 21 anonymous
0 votes
1 answer 574 views
Problem : My Environment is Nginx + uwsgi and I am very new to it. I am getting a 502 bad gateway error from Nginx on certain GET requests. It seems to be related to a length of URL.. Please find below the nginx/error.log [error] 22113#0: *1 recv ... response header from upstream, client:, server: server.domain.com, request: "GET <long_url_here>" Can somebody solve this issue?
asked Nov 27, 2019 alecxe 7.5k points
0 votes
1 answer 38 views
Problem: I have freshly migrated my project from the old python2 to the new python3 and it has hundreds of the ForeignKey relations. I have very basic knowledge related to python. Using a solution to go line by line and add on_delete argument is not the possible. What ... it does not look like catching it somehow. Looking for a Python expert who can try to fix my above Python error very quickly.
asked Jul 15 Raphael Pacheco 4.9k points
1 vote
1 answer 146 views
Problem : I am a Computer Science Student. I want to develop my website by using Django 2.1.3 and python 3.7.1. If I try to go to my websites homepage then i often face below error: Traceback: File "C:\Users\Martin\AppData\Local\Programs\Python\ ... TypeError at / Exception Value: __init__() takes 1 positional argument but 2 were given Please guide me in fixing my above django related error.
asked May 14 Martin K 6.6k points