1. 程式人生 > >Python3之外部檔案呼叫Django程式操作model等檔案實現

Python3之外部檔案呼叫Django程式操作model等檔案實現

import os
import sys
import django
sys.path.append(r'C:\Users\Administrator\PycharmProjects\your projectname')

os.chdir(r'C:\Users\Administrator\PycharmProjects\your projectname')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your projectname.settings")
django.setup()

from crm import models

v = models.Customer.objects.all()
print(v)