我在静态目录中有一些图像位于'apps / app_name'中。 我想在模型实例创建时保存这些图像。
def save(self, *args, **kwargs):
if not self.logo:
self.logo = ...
super().save(*args, **kwargs)
我试过了:
file = FileIO(os.path.join(settings.STATICFILES_DIRS[0], 'app_name/image.png'))
但我有一个错误:
The joined path (/home/.../image.png) is located outside of the base path component (/home/.../media)
这是我的settings.py:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL ='/ media /'