Thursday, August 1, 2013

Re: multiple templates fro single view

Can also use render_to_string().

--Fred
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 8/1/13 9:17 AM, Lukas Nemec wrote:
On 08/01/2013 03:04 PM, Harjot Mann wrote:
On Thu, Aug 1, 2013 at 6:10 PM, Lukas Nemec <lu.nemec@gmail.com> wrote:
Well, after some consideration,

result of a view is rendered HTML page which you send to browser,

what do you mean by rendering multiple templates?
are you talking about template inheritance = one root template which all
other templates use?

in that case, use {% extends 'root.html' %} tag,
or are you talking about splitting your big template into a few smaller?
in that cas, use {% include 'page.html' %} tag
No, I didn;t mean that.
Actually I have a function in views.py file which is hitting an html
file like this:
"return render_to_response('tcc/suspence_bill.html', dict(\
         template.items() + tmp.items()), context_instance =
RequestContext(request))"
here I want to return two html templates from this function.

Hmm. ... alright, how exactly, you have 2 different templates and you want to pass context data to both of them, and just append those two resulting html together?

so just don't return it

do this:

first try it as debug

html1 = render_to_response(template1 rendering here)
html2 = render_to_response(template 2 rendering)

try to print
print html1
print html2 # so you know if it even is representable as text because of http headers etc..

return html1 # or whatever you want

try dir(html1) if it is not a string

or dig into django shortcuts
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render


Enjoy!
Lukas

No comments:

Post a Comment