How can I force django to restart a database connection from the shell?

后端 未结 2 1789
遇见更好的自我
遇见更好的自我 2021-02-02 15:46

I have a django project on a Digital Ocean server. From my local machine, I connect to the database through ssh:

ssh -L 63333:localhost:5432 me@my.server
         


        
2条回答
  •  清酒与你
    2021-02-02 16:35

    You can use something like below

    from django.db import connections
    conn = connections['default']
    conn.connect()
    

    or

    from django.db import connection
    connection.connect()
    

提交回复
热议问题