3

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?

ojii
  • 4,729
  • 2
  • 23
  • 34
J.C Julien
  • 153
  • 2
  • 10

3 Answers3

2

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),                   
           ) 
  • Same result, in my template is just :
    field 1 field 2 field 3
    One more thing, in this template,I have an form with submit action to parse to django some text. I have made a function in javascript that stop the page to refresh. Is that a problem?
    – J.C Julien Aug 06 '15 at 15:35
  • It could be a problem yes. The post response would be displayed by refreshing whole page. If you don't want to refresh the page, use ajax query to submit the form. – Pasqual Guerrero Aug 06 '15 at 15:42
  • Thanks a lot. Now is working. But if the page is not refreshing with ajax I will have same problem. I have not worked with ajax until now – J.C Julien Aug 06 '15 at 15:47
  • Ajax allows you to send and recieve data (json) to/from the server without refreshing the page. So, where would be your problem? – Pasqual Guerrero Aug 06 '15 at 15:52
1

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}))
Abhinav Anand
  • 354
  • 2
  • 10
0

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

J.C Julien
  • 153
  • 2
  • 10