I have a static file structure like this -----> static/images/article_images/images.png
here's my settings.py
STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
# '/css/',
# 'images/article_image/',
]
here's what I tried:
{% extends "base.html" %}
{% block content %}
{% load static %} ---> i have this in my base.html
<div class="article-block" method="GET">
{% for article in articles %}
<!-- <img src="{{ article.image }}" alt="Article image"> -->
<img src="{% static '{{article.image}}' %}" alt="Article image">
<h2>{{ article.title }}</h2>
<p>{{ article.content }}</p>
{% endfor %}
</div>
{% endblock %}
here's my model.
from django.db import models
from django.conf import settings
def article_image_path(instance, filename):
return f"static/images/article_image/{filename}"
class Article(models.Model):
title = models.CharField(max_length=250)
content = models.CharField(max_length=1000)
image = models.ImageField(default='', upload_to=article_image_path)
def __str__(self):
return self.title