django insert data into database without form
To insert data into a database in Django without using a form, you can follow these steps:
- Import the model that represents the database table.
- Create an instance of the model with the data to be inserted.
- Call the
save()
method on the instance to insert the data into the database.
Here's an example:
from myapp.models import MyModel
# Create an instance of the model with the data to be inserted
new_data = MyModel(field1='value1', field2='value2')
# Call the save() method to insert the data into the database
new_data.save()