Reputation: 881
Hello when I want to test uploading images via admin panel I keep getting an error. No such file or directory: '/todoapp/media/cola.png'. I have no idea what did I wrong and unluckily I have to paste ton of code.
model:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=CASCADE)
image = models.ImageField(upload_to='media/', default='ww1.jpg')
When image goes default I get an error:
No such file or directory: '/todoapp/media/home/static/images/ww1.jpg'
urls.py
urlpatterns =+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
tree:
├── docker-compose.yml
├── Dockerfile
├── home
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── models.py
│ ├── signals.py
│ ├── static
│ │ └── home
│ │ ├── etc. etc.
│ ├── templates
│ │ └── home
│ │ ├── etc. etc.
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
├── media
│ ├── dress.png
│ └── pictures
│ └── ww1.jpg
├── requirements.txt
├── todoapp
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-39.pyc
│ │ ├── settings.cpython-39.pyc
│ │ ├── urls.cpython-39.pyc
│ │ └── wsgi.cpython-39.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── travis_script.sh
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Upvotes: 0
Views: 98
Reputation: 641
urlpatterns =+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
tree:
├── docker-compose.yml
├── Dockerfile
├── home
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── models.py
│ ├── signals.py
│ ├── static
│ │ └── home
│ │ ├── etc. etc.
│ ├── templates
│ │ └── home
│ │ ├── etc. etc.
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
├── media #chack here
│ └── ww1.jpg
│ ├── dress.png
│ └── pictures
├── requirements.txt
├── todoapp
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-39.pyc
│ │ ├── settings.cpython-39.pyc
│ │ ├── urls.cpython-39.pyc
│ │ └── wsgi.cpython-39.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── travis_script.sh
Upvotes: 1