i would like to paste media image into template but i see this:
When i click on it to show image i see:
Page not found
" C:\Users\troll\myprojects\proj\album\media\images/photos/hour.jpg " doesn't exist
I see in this address there is something with slashes, some are normal slashes and some are forward slashes - but how to change it?
my settings.py file:
MEDIA_ROOT = 'C:/Users/troll/myprojects/proj/album/media/'
MEDIA_URL = '/media/'
You should post your settings.py and urls.py for clear understanding, which version of django are you using?
still i am considering Django==1.9+
your settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# Media files
MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
MEDIA_URL = '/media/'
main urls.py
urlpatterns = [
url(r'^', admin.site.urls),
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # just after your urlspatterns
Create staticfiles directory and run command
python manage.py collectstatic
and make sure in your templates(form) you have wrote this enctype="multipart/form-data".
<form action="{% url 'index' %}" method="post" enctype="multipart/form-data">
try to debug (print) your path of image
Hope this will help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With