Open Sqlite database file directly in django

117 views
Skip to first unread message

Sourabh Jaiswal

unread,
May 22, 2018, 8:25:32 AM5/22/18
to Django users
Hi,

Is there any way to open sqlite db directly in django.

I am working on an application for which a back end script creates a database for every execution.
The database consists of multiple tables and I have to show those tables on the web site made in django.

Is there any other way around for this?

Any help will be greatly appreciated.

Thanks,
Jaiswal.

PASCUAL Eric

unread,
May 22, 2018, 10:00:17 AM5/22/18
to Django users

Hi Jaiswal,


You can use the Python sqlite3 standard lib for opening this database and manipulate it, and then display data using views written with Django.


Eric


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Sourabh Jaiswal <sourabhj...@gmail.com>
Sent: Tuesday, May 22, 2018 8:02:03 AM
To: Django users
Subject: Open Sqlite database file directly in django
 
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d24eda2f-8051-42eb-9081-b986dfd234c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

PASCUAL Eric

unread,
May 22, 2018, 10:01:52 AM5/22/18
to Django users

Re,


But you'll not be able to access the sqlite DB through Django models, since it will not have the proper schema.


Eric

From: PASCUAL Eric
Sent: Tuesday, May 22, 2018 3:59:35 PM
To: Django users
Subject: Re: Open Sqlite database file directly in django
 

Vinicius Assef

unread,
May 22, 2018, 12:58:11 PM5/22/18
to django...@googlegroups.com
It depends.

If tables have always the same schema and only their data is
different, you can use `manage.py inspectdb` [0] to create models and
develop your views.


[0] https://docs.djangoproject.com/en/2.0/ref/django-admin/#inspectdb
> https://groups.google.com/d/msgid/django-users/DB7P193MB0331365FA7C61731D9F3F0D68C940%40DB7P193MB0331.EURP193.PROD.OUTLOOK.COM.

Jimmy Cowden

unread,
May 22, 2018, 4:50:35 PM5/22/18
to django...@googlegroups.com
--

PASCUAL Eric

unread,
May 22, 2018, 5:51:30 PM5/22/18
to django...@googlegroups.com

Thanks for the tip, I didn't notice this management command before.


Eric


From: django...@googlegroups.com <django...@googlegroups.com> on behalf of Vinicius Assef <vinic...@gmail.com>
Sent: Tuesday, May 22, 2018 6:56:20 PM
To: django...@googlegroups.com

Sourabh Jaiswal

unread,
May 24, 2018, 2:22:17 AM5/24/18
to Django users
Hi,

Thanks a Lot for your reply.

Using standard python lib you are saying that I should send the data from view to template render using context dictionary.. right?

But in my case data can be huge... Is that a good way to do it?

Regards,
Sourabh Jaiswal.

PASCUAL Eric

unread,
May 24, 2018, 8:24:10 AM5/24/18
to Django users

Hi,


The content of the context dict can be anything, including of course values read from the database thanks to the sqlite3 lib. What Django generic views working with templates do is transfering for you the object field values to context entries and also automating the creation of form fields based on the model introspection.


WRT to you question about the size of the data, it depends on what you want to do. If you plan to display thousands of records in a single HTML page, it will not very efficient for sure and the browser may choke in extreme situations. To work around this, you can either implement pagination by yourself, using f.i. AJAX requests to return chunks of data as JSON packets and process them by a bit of Javascript on the client side to update your page. You can also look for JS widgets implementing this for you. I remember having used Datatables (https://datatables.net/) a while ago, and it does its job pretty well.

Create customised, editable tables in minutes with Editor for DataTables. Save your time writing yet another CRUD application - Editor is a premium extension created to produce complex, fully editable tables that take full advantage of all of the features of DataTables.
Regards


Eric


Sent: Thursday, May 24, 2018 8:22:17 AM
To: Django users

Subject: Re: Open Sqlite database file directly in django
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Vinicius Assef

unread,
May 24, 2018, 8:38:27 AM5/24/18
to django...@googlegroups.com
You can use Django to access Sqlite.
Message has been deleted

Sourabh Jaiswal

unread,
May 24, 2018, 1:33:22 PM5/24/18
to Django users
Hi Eric,

Thank for your reply.

I have implemented the table creation using context data as you suggested.
And on web page I am using Datatables to create pages. How ever with this approach whole table data is sent to browser while rendering the page.
Which is taking time as expected.

I am very new to web development. Can you please suggest me some good site from where I can make the pagination with AJAX so that only the requested data should be sent to browser.

Apart from this I have one more concern. On the web page I have to create Graphs using this data. Which I am thinking will again block me. Because if I send data chunks to browser. The Graph will be created only for that much data Not whole.

Please correct me if there is any other approach to fix this Graph problem too.

Thanks a lot in advance.

Regards,
Sourabh Jaiswal.

On Tuesday, May 22, 2018 at 5:55:32 PM UTC+5:30, Sourabh Jaiswal wrote:
Reply all
Reply to author
Forward
0 new messages