Изображение не загружается на странице
мой файл изображения не загружается на веб-странице, он показывает Атрибут 'Img' не имеет связанного с ним файла
models.py
class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
slug = models.SlugField(max_length=100,unique=True)
author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
updated_on = models.DateTimeField(auto_now= True)
content = models.TextField()
created_on = models.DateTimeField(default=timezone.now())
status = models.IntegerField(choices=STATUS, default=0)
Img = models.ImageField(null =True, blank = True, upload_to='static/images')
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.title
urls.py
from django.contrib import admin
from django.conf.urls import include
from django.urls import path
from portfo import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', views.firstpage,name='firstpage'),
path('', include('portfo.urls')),
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,"static")
]
MEDIA_URL ="/images/"
MEDIA_ROOT=os.path.join(BASE_DIR,'static/images')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
шаблон
{% for post in posts %}
<div class="card mb-4">
<div class="card-body " style="background-color: #F2F4F3;">
<img src="{{post.Img.url}}" />
<h2 class="card-title" style="margin-left:40% ;">{{ post.title|capfirst }}</h2>
<p class="card-text text-muted h6">{{ post.author }} | {{ post.created_on}} </p>
<p class="card-text">{{post.content|slice:":200" }}...</p>
<a href="/{{post.slug}}" class="btn btn-primary">Read More </a>
</div>
</div>
{% endfor %}
У меня есть файл с именем images внутри статики. Ваша помощь будет очень признательна