Reputation: 1
Django 2.0.2
cannot get the images or cannot show the images in media directory, also I defined them both media and static url and directory in setting.py
. I don't know how to write the views.py
Here is the error I am getting:
(""GET /media/Cover_jDKCLdR.jpg HTTP/1.1" 404 4542")
Thanks.
Upvotes: 0
Views: 2469
Reputation: 333
setting.py
STATIC_URL = '/static/'
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","media")
STATICFILES_DIRS=[
os.path.join(os.path.dirname(BASE_DIR), "static", "static")
]
make above changes in setting.py
to get static files and media files for your Django project
Static files for storing JS and css files.
media files for storing images
Staticonly for storing cache files which will create and stored here automatically when you run collectstatic
To load image inside the template
<img src="/media/wwww.jpg" class="img-responsive"
if you still getting confused to make this comment here i will try to help you and you can do these by following this click here!!!
Upvotes: 1