How to write a table without database in HTML in Django
<p>I just want to write a table in HTML in Django, where the data is not from Database. It seems <a href="https://django-tables2.readthedocs.io/en/latest/" rel="nofollow">django-tables2</a> is a good package that I can use in Django. However, my data is not from Database, so maybe it's not necessary to use Django model. Here comes my code of view.py and HTML page:</p>

<pre><code>def device_manager_submit(request):
    '''Switch manager page'''
    ret = rest.send_device_tor(device_name) #data from rest API exist in the form of array of dictronary: [{}, {}, {}]
    return HttpResponse(ret) #return data to HTML
</code></pre>

<p>I can use for loop in HTML to display this data but I'm not clearly about how to show them:</p>

<pre><code>    &lt;tbody&gt;
        {% for item in xx %} //I'm not sure
        &lt;tr&gt;
            &lt;td&gt;111&lt;/td&gt; //how to display?
        &lt;/tr&gt;
        {% endfor %}
</code></pre>

<p>Does anyone has any example that I can follow to display the data from view.py in HTML page</p>

<p>One way would be to use <a href="http://pandas.pydata.org" rel="nofollow">pandas</a> to load the data, and then use the <code>DataFrame.to_html()</code> to output the data into an html table. See the example below:</p>

<pre><code>import pandas as pd
data  = [{'column1': 1, 'column2': 2}]
df = pd.DataFrame(data)
html = df.to_html()
</code></pre>

<p>Html will result in:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table border="1" class="dataframe"&gt;
  &lt;thead&gt;
    &lt;tr style="text-align: right;"&gt;
      &lt;th&gt;&lt;/th&gt;
      &lt;th&gt;column1&lt;/th&gt;
      &lt;th&gt;column2&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;0&lt;/th&gt;
      &lt;td&gt;1&lt;/td&gt;
      &lt;td&gt;2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</code></pre>
</div>
</div>
</p>

<p>In a Django view this would be:</p>

<pre class="lang-python prettyprint-override"><code>@api_view(['GET'])
def showData(request):
    data  = [{'column1': 1, 'column2': 2}]
    df = pd.DataFrame(data)
    html = df.to_html()
    return HttpResponse(html)
</code></pre>

python django django-tables2