import os import sys # 添加项目根目录到Python路径 sys.path.append(os.path.dirname(os.path.abspath(__file__))) # 设置Django环境变量 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings') # 初始化Django import django django.setup() # 现在可以导入模型 from crud_book.models import CrudBookModel # 查询ID为2的图书 book = CrudBookModel.objects.filter(id=2).first() print(f'Book exists: {book is not None}') if book: print(f'File exists: {bool(book.file)}') if book.file: try: print(f'File path: {book.file.path}') print(f'File exists on disk: {os.path.exists(book.file.path)}') except Exception as e: print(f'Error accessing file path: {e}') print(f'File url: {book.file.url if book.file else None}')