13👍
✅
You can see from the source that from django.db import connection
returns a DatabaseWrapper
for the default DB. In the psycopg2 backend you’ll see that the DatabaseWrapper
accesses the low level connection via connection.cursor().connection
.
2👍
Those answers are good but not copypastable and with outdated docs so let me fix that.
As of version 3 you use the raw connection like that
from django.db import connection
stmt = "SELECT * FROM foo"
with connection.cursor() as cursor:
cursor.execute(stmt)
- Can i use celery without django
- Customize Django admin index page to display model objects
- How can I use Django Social Auth to connect with Twitter?
0👍
If you are using django 1.2+, you should probably change that to:
from django.db import connections['default']
or something equivalent.
- How to fix Error: pg_config executable not found on Elastic Beanstalk permanently
- Autocomplete field in Django
- How can create a json tree from django-mptt?
- Is django can modify variable value in template?
Source:stackexchange.com