How to write to Django DB from outside with python program?

I have some scrapers via python. That scraped data i want to add every week or month to a Django DB, so that the Data then can be used on the website.

Any suggestions how to access and write to the Django DB from a standalone python script?


Which DB engine are you using in django project?
Depending on that you have to install some dependencies and import them, the you can run SQL commands and access the tables from the database and store data within those tables.

the out of the box DB - so i guess it is sqlite3

See How to create custom django-admin commands | Django documentation | Django

You can use to run your own scripts that have full access to the Django ORM.

If you don’t want to use the ORM, then you can connect to the database using the normal Python DB API.

How can I handle exceptions and errors effectively when writing data to a Django database from an external script?

Side note: This topic has been marked as solved. Your question may get more traction if you create a new topic for it.

I also think you may need to provide more detail about the situation you’re facing. Handling errors outside of Django is fundamentally no different than inside - at least as it relates to the database if you’re using the ORM.

If you’re not using the ORM, if you’re using the DB-API directly, then you would handle the exceptions that it creates.