1

Resolved

django template doesn't work with 1.7

description

which is the default because we grab django<2 in requirements.txt


ValueError at /
dictionary update sequence element #0 has length 11; 2 is required


Request Method:
GET

Request URL:
http://localhost:51300/ Django Version: 1.7

Exception Type:
ValueError

Exception Value:
dictionary update sequence element #0 has length 11; 2 is required


Exception Location:
c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\template\context.py in init, line 19

Python Executable:
c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\Scripts\python.exe

Python Version:
3.4.1

Python Path:
['c:\users\sara\documents\visual studio '
'2013\Projects\AzureDemo\DjangoWebProject1',
'C:\WINDOWS\SYSTEM32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'c:\users\sara\documents\visual studio '
'2013\Projects\AzureDemo\DjangoWebProject1\env',
'c:\users\sara\documents\visual studio '
'2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages']


Server time: Tue, 2 Sep 2014 21:21:27 -0700


Traceback Switch back to interactive view


Environment:


Request Method: GET
Request URL: http://localhost:51300/ Django Version: 1.7
Python Version: 3.4.1
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'app')
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:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\core\handlers\base.py" in get_response
  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\app\views.py" in home
  2. 'year':datetime.now().year,
    File "c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\shortcuts.py" in render
  3. return HttpResponse(loader.render_to_string(*args, **kwargs),
    File "c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\template\loader.py" in render_to_string
  4. with context_instance.push(dictionary):
    File "c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\template\context.py" in push
  5. return ContextDict(self, *args, **kwargs)
    File "c:\users\sara\documents\visual studio 2013\Projects\AzureDemo\DjangoWebProject1\env\lib\site-packages\django\template\context.py" in init
  6. super(ContextDict, self).__init__(*args, **kwargs)
Exception Type: ValueError at /
Exception Value: dictionary update sequence element #0 has length 11; 2 is required

comments

feechl wrote Sep 5 at 6:59 AM

In views, I've replaced this:
RequestContext(request,
        {
            'title':'Home Page',
            'year':datetime.now().year,
        })
with:
        {
            'title':'Home Page',
            'year':datetime.now().year,
        }

Zooba wrote Sep 5 at 1:09 PM

Thanks. Hopefully that will keep people going until we get our next update out.

We have most of a fix ready for 2.1, just debating how we should go about supporting older versions of Django in our templates. (Currently it works for 1.4-1.6, but 1.7 has more significant breaking changes.)

reinierdg wrote Fri at 6:39 AM

With Django 1.4 it also does not work because of the templating change:

layout.html
                <ul class="nav navbar-nav">
                    <li><a href="{% url 'home' %}">Home</a></li>
                    <li><a href="{% url 'about' %}">About</a></li>
                    <li><a href="{% url 'contact' %}">Contact</a></li>
                </ul>
With 1.4 it should be:
                <ul class="nav navbar-nav">
                    <li><a href="{% url home %}">Home</a></li>
                    <li><a href="{% url about %}">About</a></li>
                    <li><a href="{% url contact %}">Contact</a></li>
                </ul>
This is also the case for loginpartial.html.

Zooba wrote Fri at 6:36 PM

Unfortunately, that fix breaks the template for 1.7.

In the long run, we want to help people migrate to the newer versions of libraries, and we think that most people creating these templates will want to run against the newest Django, so we won't be changing it.

But thanks for pointing out the fix. Hopefully people using older versions of Django with our templates will find it here.