G
G
Grigory Dikiy2016-01-27 14:56:11
Django
Grigory Dikiy, 2016-01-27 14:56:11

Can't display Django image?

Good day, I can not display the images that are uploaded to the site through the model. I looked at related questions on the toaster, their solutions did not help either.

# Model
...
image = models.ImageField(upload_to='image/')
...

#Urls
urlpatterns = [
    url(r'^portfolio/', include('portfolio.urls')),
    url(r'^auth/', include('loginsys.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^', include('article.urls')),
]  + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

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

#Template
<li><img src="{{ item.image }}" alt="" /></li>

Project structure: Project
root: -> media -> image -> image itself
Solution (@sim3x):
The last line in urlpatterns blocked everything, the solution was this:
urlpatterns = [
    url(r'^portfolio/', include('portfolio.urls')),
    url(r'^auth/', include('loginsys.urls')),
    url(r'^admin/', admin.site.urls),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [url(r'^', include('article.urls'))]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-01-27
@frilix

<li><img src="{{ item.image.url }}" alt="" /></li>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question