Django媒体图片未显示

时间:2018-06-30 12:27:18

标签: django media

我正在开发django应用程序,因为我正在通过管理面板上传图像 我已经在其他应用程序中实现了此功能,但是我似乎可以按以下方式获取配置的问题

settings.py

STATIC_URL = '/static/'
AUTH_USER_MODEL = 'ntakibariapp.Member'
LOGOUT_REDIRECT_URL = 'ntakimbari:_login'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),

urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('ntakibariapp.urls')),
    path('accounts/', include('django.contrib.auth.urls'))
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, ducument_root=settings.MEDIA_ROOT)

models.py

class Community_work(models.Model):
    where = models.CharField(max_length=80)
    time = models.TimeField(blank=False)
    date =  models.DateField(blank=False)
    image_of_area = models.ImageField(upload_to='photos',blank=True)
    post_date = models.DateTimeField(default=timezone.now)

    def __str__(self):
        return self.where

template / communtity_work.html

{% extends 'temp/base.html' %}
{% block title %}community works{% endblock %}
{% block body %}

<div class="container">
  {% for work in works %}
   <p>Picture of the area <img src="{{work.image_of_area.url}}"></p>
   <p>Where: {{work.where}}</p>
   <p>Time: {{work.time}}</p>
   <p>Date: {{work.date}}</p>
  {% endfor %}
</div>
{% endblock %}

2 个答案:

答案 0 :(得分:1)

在urls.py中,您尝试使用拼写错误 document_root 而不是ducument_root

答案 1 :(得分:0)

标签也不应该是<img src="{{community_work.image_of_area.url}}">吗?