0

I'm trying to filter (by column element) and display information from a sqlite3 database directly onto a HTML table. I've read in multiple places that you should use Django's ORM instead of a database. However, the data is continuously updating in the database so I'm not sure if this is a route to pursue with this. TL;DR I'm looking for a way to open a sqlite3 .db file and chuck it into an HTML table.

I have looked over the django documentation regarding models, as well as looked at several different websites/tutorials (here, stack overflow; I even found django-tables2 which I thought was going to work), all to no avail. I'm essentially at a roadblock and I'm not sure where to go and/or what to do.

Here is how the database is structured:

---------------------------------------------
| Name | Type | Col 1 | ... | Col N | Color |
---------------------------------------------
| Gary | A    | Data  | ... | Data! | Green |
| Mark | A    | Data  | ... | Data? | Blue  |
| Ray  | B    | Data  | ... | Data. | Red   |
...

As far as the HTML is concerned, I'd like to use for loop similar to this:

<table>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Col 1</th>
        ...
        <th>Col N</th>
    </tr>
        {% for row in data %}
    <tr> 
        <td>{{ row }}</td>
    </tr>
    {% endfor %}
</table>

One thing to note as well is that the last column in the above sample database is not being shown on the table.

2
  • Do you need to use Django? datasette might be more suited for this. Commented Jun 29, 2019 at 21:17
  • You also don't need to use the Django ORM, you can still import sqlite3 and use dataTables to show the data. It's a bit hard to know what you need here Commented Jun 29, 2019 at 21:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.