0

I learn Django and I have a problem with display img in settings I add:

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

and in url.py I add static

urlpatterns = [
  //routing
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

Problem is that img is uploading correctly but I have a problem with display that. For example - in my template I have img tag:

<img src="{{MEDIA_URL}}{{film.plakat}}">

But it doesn't display that. I inspect img that and src contain "/media/plakaty/test.jpg". I go to

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

admin/
filmy/
login/ [name='login']
logout/ [name='logout']
^media/(?P<path>.*)$
The current path, media/plakaty/test.jpg, matched the last one.

What is wrong?

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
  • Is `film` an instance of a model and `film.plakat` an ImageField on that model? Try `{{ film.plakat.url }}` if so – Iain Shelvington May 15 '22 at 12:24
  • Yes, this instance exist in this model. In first time. In first time I saw that in page error I have bad path. It dispaly `“C:\Users\michal\django\moje_media\plakaty\test.jpg”` but in the fact correct path was `C:\Users\michal\django\mysite\plakaty\test.jpg`. But I copy this folder to follow folder but it doesn't solve my problem. – HelloSass8273 May 15 '22 at 12:43

0 Answers0