import os import sys ROOT = 'settings.py所在目录' sys.path.append(ROOT) from django.core.management import setup_environ import settings setup_environ(settings)