[英]Access Django DB from Task
Is it possible to update the DB from a Django App, from an Other python Script. 是否可以从Django应用程序和其他python脚本更新数据库。 The plan is to fetch Sensor Data over an Tcp/ip Connection, Write it to the DB and the Django app can Display the values.
计划是通过Tcp / ip连接获取传感器数据,将其写入数据库,并且Django应用可以显示这些值。
Thanks 谢谢
Sure, all you have to do is to import the project settings. 当然,您要做的就是导入项目设置。
import os
sys.path.append('relative/path/to/settings/file')
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
After that you just import all the models you want to work with, also do the append the directory to them (models.py). 之后,您只需导入要使用的所有模型,还可以将目录追加到它们(models.py)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.