0

I'm having hard time to display media on local system.. the problem is that:

{{ producer.img.url }}

gives me a url path relative to the page I'm browsing, so it always fails to locate the file. It actually prints something like:

media/media/djprofiles/john_0VtCrdA.jpg

which obviously fails (note the missing initial "/").

Following Django docs, I added in my urls.py:

urlpatterns = [
    url(r'^i18n/', include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns(
    ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

and settings.py is as follow:

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

The img field is defined in models.py as follow:

img = models.ImageField(upload_to=settings.MEDIA_URL + 'djprofiles')

I know there are already many questions relative to showing media on local system, but none seems to provide me with a working solution.

davideghz
  • 3,596
  • 5
  • 26
  • 50

1 Answers1

0

did you try

MEDIA_URL = '/media/'

in settings.py?

  • yes, that was part of the solution, along with `img = models.ImageField(upload_to='djprofiles', null=True, blank=True)` – davideghz Aug 09 '17 at 19:17