Django中不能上传任何文件和图像

时间:2022-12-05 19:36:46

I have a model like this:

我有一个这样的模型:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    avatar = models.ImageField(blank=True, upload_to='hi/')

And Setting.py like this:

和设置。py是这样的:

MEDIA_ROOT = os.path.abspath(os.path.dirname(__name__)) + '/media/'
MEDIA_URL = '/media/'

But I can't upload any images or even create or save any UserProfile objects.

但是我不能上传任何图片,甚至不能创建或保存任何UserProfile对象。

1 个解决方案

#1


1  

change MEDIA_ROOT set line to this:

将MEDIA_ROOT设置行更改为:

MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__name__)), 'media')

#1


1  

change MEDIA_ROOT set line to this:

将MEDIA_ROOT设置行更改为:

MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__name__)), 'media')