frozen.txt" where is..." /> frozen.txt" where is..." /> frozen.txt" where is..."/>

Django-cms render_to_response doesn't render to template

708 views Asked by At

I am working on a project in django 1.5.12. version with django-cms installed . I have a file generated by command "pip freeze > frozen.txt" where is next information with what I have installed:

Django==1.5.12
MySQL-python==1.2.5
South==1.0.2
argparse==1.2.1
distribute==0.6.24
django-classy-tags==0.6.2
django-cms==2.4.3
django-mptt==0.5.2
django-sekizai==0.8.2
html5lib==1.0b7
six==1.9.0
wsgiref==0.1.2

Well, my problem is that I have an app in my project where I have next code in views.py:

from django.shortcuts import *
def test(request):

    data = {'test 1': [ [1, 10] ], 'test 2': [ [1, 10] ],'test 3':[ [2,20]] }
    print data                  # to see if function works 
    return render_to_response("project_pages.html",{'data':data},context)

And in my template project_pages.html I have this :

<table>
    <tr>
        <td>field 1</td>
        <td>field 2</td>
        <td>field 3</td>
    </tr>

    {% for author, values in data.items %}
    <tr>
        <td>{{author}}</td>
        {% for v in values.0 %}
        <td>{{v}}</td>
        {% endfor %}
    </tr>
    {% endfor %}
</table>

and isn't render the response to the template. And in terminal doesn't show me any errors. The function is working because it is printing data.

If try to return something like this:

return render_to_response("project_pages.html",{'data':data})

without context at the end (it is different call) it gives me next error:

"You must enable the 'sekizai.context_processors.sekizai' template "
TemplateSyntaxError: You must enable the 'sekizai.context_processors.sekizai' template context processor or use 'sekizai.context.SekizaiContext' to render your templates.

In my settings.py I have sekizai:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.i18n',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'cms.context_processors.media',
    'sekizai.context_processors.sekizai',
    'sekizai.context.SekizaiContext',

)

So, what should I do?

3

There are 3 answers

4
Pasqual Guerrero On BEST ANSWER

Review what context variable have. It should have something like that:

Example:

from django.template import RequestContext

def view(request):
   ...

   return render_to_response(
                "project_pages.html",
                {'data':data}, 
                context_instance=RequestContext(request),                   
           ) 
0
J.C Julien On

I figured out.

In this template I have some information that i don't wanna lose when a user press a button to submit some information to django to process, so I've made a function in javascript that allows to submit but doesn't refresh the page. With no refresh the content stays static and data variable from response isn't send to template

0
Abhinav Anand On

For people coming here to look for django 1.8 or later should use the below code. Now the template context processor is not picked from the setting.py file direclty, if you are writing custom views.

use the code below to make it work:

from sekizai.context import SekizaiContext

def view(request):
...


    return render_to_response('template.html', 
                            SekizaiContext(request, {'data': data}))