Answer the question
In order to leave comments, you need to log in
Why aren't images shown from CharField in django?
The problem is this:
The folder where images are uploaded by a potential user is the media folder.
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', include('homepage.urls')),
path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
{% if latest_categories %}
{% for a in latest_categories %}
<a href="#">{{a.name_category}}</a>
<img src="{{a.img_category.url}}">
{% endfor %}
{% else %}
Категории не найдены.
{% endif %}
<a href="#">fuckmybrain</a>
<img src="/media/category/backg.jpg">
<a href="#">Кирпичи</a>
<img src="/media/category/d90f68079558e8edfd1cce75ffa0e04c.jpg">
<a href="#">Металлопрокат</a>
<img src="/media/category/7962256765.jpg">
<a href="#">Пиломатериал</a>
<img src="/media/category/%D0%9F%D0%B8%D0%BB%D0%BE%D0%BC%D0%B0%D1%82%D0%B5%D1%80%D0%B8%D0%B0%D0%BB.jpg">
Answer the question
In order to leave comments, you need to log in
You added a line to urls.py to support STATIC_URL/STATIC_ROOT, but media files need support for MEDIA_URL/MEDIA_ROOT
https://docs.djangoproject.com/en/2.2/howto/static...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question