fpghost
fpghost

Reputation: 2944

Django and external sqlite db driven by python script

I am just beginning learning Django and working through the tutorial, so sorry if this is very obvious.

I have already a set of Python scripts whose ultimate result is an sqlite3 db that gets constantly updated; is Django the right tool for turning this sqlite db something like a pretty HTML table for a website?

I can see that Django is using an sqlite db for managing groups/users and data from its apps (like the polls app in the tutorial), but I'm not yet sure where my external sqlite db, driven by my other scripts, fits into the grand scheme of things?

Would I have to modify my external python scripts to write out to a table in the Django db (db.sqlite3 in the Django project dir in tutorial at least), then make a Django model based on my database structure and fields?

Basically,I think my question boils down to:

1) Do I need to create Django model based on my db, then access the one and only Django "project db", and have my external script write into it.

2) or can Django utilise somehow a seperate db driven by another script somehow?

3) Finally, is Django the right tool for such a task before I invest weeks of reading...

Upvotes: 0

Views: 1541

Answers (2)

Emam
Emam

Reputation: 620

If you care about taking control over every single aspect of how you want to render your data in HTML and serve it to others, Then for sure Django is a great tool to solve your problem.

Django's ORM models make it easier for you to read and write to your database, and they're database-agnostic. Which means that you can reuse the same code with a different database (like MySQL) in the future.

So, to wrap it up. If you're planning to do more development in the future, then use Django. If you only care about creating these HTML pages once and for all, then don't.

PS: With Django, you can easily integrate these scripts into your Django project as management commands, run them with cronjobs and integrate everything you develop together with a unified data access layer.

Upvotes: 1

Lie Ryan
Lie Ryan

Reputation: 64837

Django can use different databases, sqlite is the easiest one to setup since python standard library comes with everything it needs for sqlite, while you generally need separate software to setup other databases. That's why it's used in the tutorial.

Django core itself does not require a database. You can setup a django based site without a database. However many of the modules like the authentication module does require database setup.

You don't have to write models, you can create a connection with DBAPI or other database drivers directly inside django. Of course, this means that parts of the framework that integrates with the ORM wouldn't be aware of the database connection you create yourself, like the Form class, the generic view, or the automatic admin view, so you'll be missing these features that makes Django very powerful framework.

You can create unmanaged models to allow many parts of django to be aware of your existing database and utilize Django's more advanced features with your existing database. See https://docs.djangoproject.com/en/dev/howto/legacy-databases/

Upvotes: 0

Related Questions