1

I have a django project based on django 1.11.
I uploaded media files and try to get them but instead I get nothong.
I read documentation and did exactly as it said.
Also I checked 'media' foleder permissions.

settings.py:

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

urls.py:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('myapp.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
8
  • Did you get 404 error? Commented Dec 23, 2018 at 19:07
  • No, If I try to open an image by a direct link '127.0.0.1:8000/media/unsplash.jpg' I get the 'index' page. Commented Dec 23, 2018 at 19:16
  • But actually I think it's 404. Because if I add "$" to url in my app then I get 404 Commented Dec 23, 2018 at 19:18
  • Did you use nginx in server? Commented Dec 23, 2018 at 19:19
  • I found my image in '127.0.0.1:8000/media/media/unsplash.jpg' I have no idea why ...media/media.. Commented Dec 23, 2018 at 19:27

1 Answer 1

2

Change your MEDIA_ROOT to MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') in settings.py and make sure your media file in project root directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.