from django.core.files.storage import default_storage from django.core.files.base import ContentFile content = ContentFile(b"Hello World!") path = default_storage.save('test_file2.txt', content) print(f"文件保存路径: {path}") # 测试文件读取 if default_storage.exists(path): with default_storage.open(path, 'r') as f: content = f.read() print(f"文件内容: {content}") # 测试文件URL生成 url = default_storage.url(path) print(f"文件URL: {url}") # 测试文件删除 default_storage.delete(path) print(f"文件是否存在: {default_storage.exists(path)}")