Answer the question
In order to leave comments, you need to log in
Media images not showing in django?
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = '/media/'
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('annex.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
class Company(models.Model):
name = models.CharField("Название компании", max_length = 80)
city = models.CharField("Город", max_length = 80)
background = models.ImageField("Фон", upload_to="annex/img/%Y/%m/%d", default='')
{% load static %}
{% block content %}
<div class="banner-bg --not_banner" id="top">
{% for items in object_list %}
<div class="with-company col-md-4">
<div class="col-xs-12">
<div class="banner-overlay"></div>
<div class="content-company">
<div style="background: url({{items.background.url}});" class="welcome-text">
...
Answer the question
In order to leave comments, you need to log in
style="background: url('{{items.background.url}}');" - in quotes {{items.background.url}} take
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question