开发者

Can i access different database in django than other default database

开发者 https://www.devze.com 2023-03-08 14:31 出处:网络
I have the database backup script in python which insertssome data in mysql database . Now my Django is in different database.

I have the database backup script in python which inserts some data in mysql database .

Now my Django is in different database.

How can i access different database because i don't have any objects in Mo开发者_运维百科dels.py. i want to display some data in django interface


Yes, you can setup multiple database and access every one of them. you can get the specified database connection cursor using this:

from django.db import connections
cursor = connections['my_db_alias'].cursor()

where my_db_alias is your another db alias .

check the doc:

https://docs.djangoproject.com/en/1.3/topics/db/multi-db/

0

精彩评论

暂无评论...
验证码 换一张
取 消