Django-cms render_to_response does not render template

I am working on a project in django 1.5.12. versions with django-cms installed. I have a file created by the command "pip freeze> frozen.txt" where the following information is with what I 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

      

Ok my problem is I have an application in my project where I have the following 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 does not display the response to the template. And there are no errors in the terminal. The function works because it prints data.

If you try to return something like this:

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

      

without context at the end (this is another call) it throws the following 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


source to share


3 answers


View the context variable. It should have something like this:

Example:



from django.template import RequestContext

def view(request):
   ...

   return render_to_response(
                "project_pages.html",
                {'data':data}, 
                context_instance=RequestContext(request),                   
           ) 

      

+2


source


For people coming here looking for django 1.8 or newer, the code below should be used. Now the template context handler is not fetched from the setup.py direclty file if you write custom views.

use the below code to make it work:



from sekizai.context import SekizaiContext

def view(request):
...


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

      

+1


source


I understood.

In this template I have information that I don't want to lose when the user clicks a button to submit some information to django for processing, so I created a function in javascript that allows the page to be submitted but not refreshed. Without updating, the content remains static and the data variable from the response is not sent to the template

0


source







All Articles