Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.10: ValueError: dictionary update sequence element #0 has length xx; 2 is required #20

Open
florianm opened this issue Oct 21, 2016 · 0 comments
Labels

Comments

@florianm
Copy link

florianm commented Oct 21, 2016

Hi folks, just got first light on some sweet PDF output from your neat extension but I'm running into a weird bug in django-rest-framework.

Environment

  • Django 1.10.2
  • django-rest-swagger==2.0.7
  • djangorestframework==3.5.0
  • djangorestframework-csv==1.4.1
  • djangorestframework-filters==0.8.1
  • djangorestframework-gis==0.10.1
  • djangorestframework-jsonp==1.0.2
  • djangorestframework-yaml==1.0.3
  • dynamic-rest==1.5.0
  • rest-framework-latex==0.0.9

config:

TEMPLATES = [
    {
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
[...]

Expected

PDF output via rest-framework-latex

Error

Accessing an API view with rest-framework-latex's renderer enabled throws a

ValueError
dictionary update sequence element #0 has length 13; 2 is required

Hack

Change rest_framework/compat.py from

# backends template, e.g. django.template.backends.django.Template
    else:
        return template.render(context, request=request)

to

# backends template, e.g. django.template.backends.django.Template
    else:
        return template.render(dict(data=context), request=request)

so I can access it in my latex template like so

{% for obj in data %}
 {{ obj.some_field_that_my_api_exports|latex_safe }}
{% endfor %}

context is originally an OrderedDict of my queryset.
This is apparently absolutely required by all other renderers like the Browseable API renderer.
However, I couldn't figure out a way to access the OrderedDict in my template without wrapping it into a dict.

Unless I'm missing a straight-forward way to access the OrderedDict from the template, would it be possible to change LatexRenderer.render() to wrap data into a normal dict?

        tex = super(LatexRenderer, self).render(
            {"data": data}, accepted_media_type, renderer_context)

Sending PR for review and discussion.

@florianm florianm changed the title [Solution] Django 1.10: ValueError: dictionary update sequence element #0 has length xx; 2 is required Django 1.10: ValueError: dictionary update sequence element #0 has length xx; 2 is required Oct 21, 2016
@scott-w scott-w added bug and removed bug labels Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants