django model项目外操作

方法1:

python manage.py shell

然后import对应的model并操作

方法2:

新建py脚本

import sys
import os

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MxShop.settings')
# print(os.environ)

import django
django.setup()

from goods.models import GoodsCategory

all_category = GoodsCategory.objects.all()

猜你喜欢

转载自www.cnblogs.com/chenyishi/p/10649876.html
今日推荐