A
A
andreika_big2021-05-02 20:44:01
Django
andreika_big, 2021-05-02 20:44:01

Getting data from server?

Help, please, I don’t know how to get data from the DJANGO database.
I need to do this from a third-party application that is not connected to the server
Created a model

class Visited(models.Model):
    latitude = models.DecimalField(max_digits=8, decimal_places=6)    # широта
    longitude = models.DecimalField(max_digits=9, decimal_places=6)   # долгота
    country = models.CharField(max_length=200)

    def __str__(self):
        return self.country


Added it to the database, added data
When the server is running (local), I want to pull this data from the database with a request to the server
Thank you very much

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yupiter7575, 2021-05-02
@yupiter7575

cry

S
soremix, 2021-05-02
@soremix

It's not clear what exactly is needed.

I want to pull this data from the database with a request to the server

Create a view that will accept your request in views.py, import the Visited model in the same file, and then just ORM . Well, do not forget about urlpatterns.
Let's say there is a mainapp application, it has views.py and models.py
# urls.py

urlpatterns = [
    path('get-records/', views.get_records, name='get-records'),
]

# views.py

from mainapp.models import Visited

# вьюха, которая обрабатывает ваш запрос
def get_records(request):
    all_entries = Visited.objects.all()

   # ну и дальше уже что там нужно с ними

G
gromyko21, 2021-05-03
@gromyko21

Learn what api is. And make http requests to the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question