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>You don't need to return Django objects to create templates, you can use any data. The <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#render" rel="nofollow">render()</a> function allows you to combine context with the regular HttpResponse. You pass it the request which was given to the view calling it, the name of the template you want to render, and then a dictionary of data to provide to the template.</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 render(request, 'some_template.html', {'devices': ret}) #return data to HTML
</code></pre>

<p>Assuming that <code>ret</code> contains some objects with a <code>name</code> and <code>description</code>, we can loop through <code>devices</code> like so:</p>

<pre><code>&lt;tbody&gt;
        {% for device in devices %} 
        &lt;tr&gt;
            &lt;td&gt;{{ device.name }}&lt;/td&gt;
            &lt;td&gt;{{ device.description }}&lt;/td&gt;
        &lt;/tr&gt;
        {% endfor %}
</code></pre>

python django django-tables2