On my Django website When I am making DEBUG = True
Images are not loading.
Please find my Dir structure and code.
Settings.py
STATIC_DIR=os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/admin/'
STATICFILES_DIRS=[
STATIC_DIR,
]
MEDIA_URL = "/abcd/"
MEDIA_ROOT = BASE_DIR
INSTALLED_APPS = [
------
'django.contrib.staticfiles',
-- - - - - -
]
Models.py
class Product(models.Model):
" " "
- -- - - -- - -
image = models.ImageField(upload_to='upload/products/', default='',null=True, blank=True)
"""""""""
class PostImage(models.Model):
post = models.ForeignKey(Product, default=None, on_delete=models.CASCADE)
image = models.ImageField(upload_to='upload/products/')
urls.py from django.conf.urls.static import static
urlpatterns = [
""""""",
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
HTML file:
{% if product.image %}
<img class="rounded-circle" src="{{product.image.url}}" alt=".." height="45px" width="45px">
{% endif %}
here If I am changing Debug=False It is working as expected but when it is True images are not loading and in admin page CSS is not working.
Can anyone help me with steps on how to resolve this problem?