instead of using render_to_response
which will send the HTML output back to browser.
I would like to take the results, generate HTML (using templates) & output the html into a variable in my views.py
. How can I do this?
You can create a HTML form and can submit the form using post method if you do not want to pass values in url. In the same way you can pass multiple parameters. add {% csrf_token %} to the form.
{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.
To comment out a block of code in a Django template, use the {% comment %} and {% endcomment %} tags and pass the code to not render between the tags.
The URL template tag is a typical type of Tag in the Django Template Language framework. This tag is specifically used to add View URLs in the Template Files.
SOLVED! the way to do this -
from django.template.loader import render_to_string rendered = render_to_string('my_template.html', { 'foo': 'bar' })
thanks to ned for pointing to the Django docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With