Closed Dmitri-Sintsov closed 9 years ago
Changed to
t = loader.get_template('partial_feed.htm')
c = RequestContext(request, {'feed': feed}, processors=[template_context_processor])
feed_html = t.render(c)
Now it produces: dictionary update sequence element #0 has length 0; 2 is required
t = loader.get_template('partial_feed.htm')
c = RequestContext(request, {'feed': feed})
feed_html = t.render(c)
does not work with the same exception.
Here are parts of settings.py:
TEMPLATES = [ { "BACKEND": "django_jinja.backend.Jinja2", "APP_DIRS": True, "OPTIONS": { "match_extension": ".htm", "app_dirname": "jinja2", 'context_processors': [ 'ispdev.context_processors.template_context_processor' ] } }, { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
django-jinja works fine when rendering to response render(request,...) however it's a AJAX JSON response so I need to render to string.
t = loader.get_template('partial_feed.htm')
feed_html = t.render(request=request, context={
'feed': feed
})
raises no exception but returns empty string. When debugging in django executions of jinja2 script ends at:
<p>{{ feed.linkify_post()|safe }}</p>
which is strange, because the same partial_feed.htm renders fine with non-AJAX render() shortcut response.
I'm not clearly understand your problem. But for rendering to string you has this shortcut https://docs.djangoproject.com/en/1.8/topics/templates/#django.template.loader.render_to_string
And django-jinja has tests for it, that successfully pases: https://github.com/niwinz/django-jinja/blob/master/testing/testapp/tests.py#L84
Sorry it was my silly mistake. I defined partial_feed.htm as jinja2 macro and obviousely macro does not execute itself when rendering. That's why empty string was returned. Sorry for taking your time.
The line feed_html = t.render(c) raises Traceback: File "/home/user/work/ispdevenv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
Exception Type: ValueError at /blog-1/feed-add/ Exception Value: dictionary update sequence element #0 has length 8; 2 is required Request information: GET: No GET data