How does Django access data in sqlite database?
Lets assume this scenario:
Very basic models.py
, and views.py
are created to accept user input from page and store it in sqlite
database. If a user clicks a submit button, that data is sent to sqlite
database, and the user can view it by accessing the Django Admin
page. Later the user wants to display the stored data using CBV in views.py
:
class Some_ListView(ListView):
template_name = 'some_list.html'
context_object_name = 'SomeInfo'
model = models.SomeModel
And the data in the database is rendered in HTML
like this:
{% for item in SomeInfo %}
<p>item<p>
{% endfor %}
When & how does Django load data when rendering a page? Does it access & retrieve data whenever a any html page is loaded? Is there any way to load data in a previous page, temporarily store it, and inject it in a future page? How do you get connection? Does it use connection pool?
I will be using PostgreSQL for database for my real project, and I'm looking for advice on when & how to establish connection using connection pool.
Another scenario:
Some data were prepared by creating Class WellInfo
in models.py
. You can view this data in Django Admin
page:
Using these data, I was able to make a list page using ListView
like this:
Upon clicking any of the row, user will be navigated to a page that renders that object instance's data. So if a user clicks University Well
, user will reach a page that has data relevant only to University Well
. And I did so without explicitly telling Django to use only that object. I only set up primary key url using api
. How did Django know to display only University Well
's data, but not the others?