天道酬勤,学无止境

脚本调用

The script calls the django module separately

Demand scenario:When writing django, we sometimes encounter that we need to use the model in django, but the script code is executed separately, not executed together with the django service. At this time, you need to make the following settings at the beginning of the file :import os, sys CMDB_PATH = os.path.dirname(os.path.dirname(__file__)) sys.path.insert(0, CMDB_PATH) os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'import django django.setup() Origin:https://blog.51cto.com/lovejxs/2726604

2021-05-14 04:53:26    分类:博客    django模块   脚本调用