Respond as view without template

Greetings,
i have index file that have a variables that was passed from view that have a template html file where it reads this for example:
template.html

<tr>
  <th>cnt</th>
  <th>dt</th>
  <th>dt_a</th>
  <th>dt_first</th>
  <th>dt_last</th>
  <th>dt_1</th>
</tr>
{% for i in order %}
<tr> 
  <tr> 
   <td>{{ i.cnt }}</td>
   <td>{{ i.dt }}</td>
   <td>{{ i.dt_a }}</td>
   <td>{{ i.dt_first }}</td>
   <td>{{ i.dt_last }}</td>
   <td>{{ i.dt_1 }}</td>
</tr>
{% endfor %}

It is feeding the main html table.
What i would like to ask, how it is possible to make it happen without the template html file.
I would make multiline variable like this for example in a view:

data="""<tr>
  <th>cnt</th>
  <th>ip</th>
  <th>ports</th>
  <th>dt_first</th>
  <th>dt_last</th>
  <th>dt_ban_till</th>
</tr>
{% for i in order %}
<tr> 
  <tr> 
   <td>{{ i.cnt }}</td>
   <td>{{ i.dt }}</td>
   <td>{{ i.dt_a }}</td>
   <td>{{ i.dt_first }}</td>
   <td>{{ i.dt_last }}</td>
   <td>{{ i.dt_1 }}</td>
</tr>
{% endfor %}"""

maybe some breaklines is needed. How can i achive to send template from view with variable without html template file. Thank you

  1. Can you explain why you don’t want to use a template file?
  2. You can create a template from a string directly with the Template class, see The Django template language: for Python programmers | Django documentation | Django
1 Like
  1. I will be using it sometimes when i need to share between views. But i see it pointless when i need some short info to be updated dynamicly to make additional file for each table that i want to refresh.
    Less files,less headache :smiley:

2.Thank you! This is what i want, will test it :>

Are you looking at a situation where, if your table changes, you would need to make two modifications to your code? (Or code and template?) If so, I would suggest that you want it to be two template files to begin with. One would be your basic template for the table without the “row fragment”, the other one would be just the row fragment.
You can use the include tag in your table template to use the row fragment template, and then use that row fragment template for your update view.

hmmmm interesting idea, thank you. Will test it too.
Thank you.
P.S. Yes, the less files i need to open, less confusion in the future when the app will expand.