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.