79👍
✅
You can use something like below
from django.db import connections
conn = connections['default']
conn.connect()
or
from django.db import connection
connection.connect()
8👍
from django.db import connections, connection
for conn in connections.all():
conn.close_if_unusable_or_obsolete()
then call connection.cursor will get a fresh connection,
django source code:
def _cursor(self, name=None):
self.ensure_connection()
with self.wrap_database_errors:
return self._prepare_cursor(self.create_cursor(name))
👤Icy
- [Django]-Whats the difference between using {{STATIC_URL}} and {% static %}
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-Django: add image in an ImageField from image url
Source:stackexchange.com