我是励志哥

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()

  

posted @ 2021-09-11 14:59  python黑客编程  阅读(99)  评论(0编辑  收藏  举报