setting.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
urls.py(project)
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
class Article(models.Model):
title = models.CharField(max_length=100)
text = models.TextField()
image = models.ImageField(upload_to='images/', blank=True, null=True)
#is_published = models.BooleanField(default=True)
views.py
def image(request):
images = Article.objects.all()# тут objects
return render(request, 'news/index.html',{'images':images})
template
{% for im in images %}
<div class="list_one">
<p>{{ im.title }}</p>
<img src="{{ im.image.url }}>
{% endfor %}