django在项目中创建测试脚本
import os import sys import django import time import uuid BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # 定位到django根目录 sys.path.append(os.path.abspath(os.path.join(BASE_DIR, os.pardir))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test1.settings") # django的settings文件 django.setup() def test(): from booktest.models import BookInfo # book_obj = BookInfo(title="三国演义", title_id=1) book_obj = BookInfo.objects.filter(title_id=1) # time_id = uuid.uuid5 # print(time_id) # book_obj.save() # for book in book_obj: # print(book.title) for obj in book_obj: # print(11111111111111) print(obj.title) print(book_obj) if __name__ == '__main__': test()
生前无需久睡,死后自会长眠,努力解决生活中遇到的各种问题,不畏将来,勇敢面对,加油,你是最胖的,哈哈哈