Answer the question
In order to leave comments, you need to log in
How to add list to db using django?
I need that when clicking on a button in HTML, a process would be performed that would automatically take the created list (list) of the ping and fill, directly, the ping and the hostname into the database table through django.
The list itself.
from pythonping import ping
def pingchecker():
Response_List = ping('google.com', timeout=60, count=60, interval=1, verbose=True, df=True)
return Response_List._responses #Сам список
Answer the question
In order to leave comments, you need to log in
If you use the Dzhang ORM, then everything is done through the model. You create, for example, a PingResult model, in which there will be a ping_list field with the JSON type, and then save the json with the list there.
If there was a PostgreSQL database, then you can create fields with the Array type in it - just for lists.
If ORM is not used and you need to put data into a ready-made database, into a specific table and field, then use a "raw" query:
from django.db import connection
with connection.cursor() as cursor:
cursor.execute('INSERT INTO sometable (somefield) VALUES (ping_list)');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question