Django 已归档以加载资源:服务器响应状态为404(未找到)
我的图像未加载到模板中。我把他们放在管理,所以一切都应该是好的,但,没有。 模型场Django 已归档以加载资源:服务器响应状态为404(未找到),django,Django,我的图像未加载到模板中。我把他们放在管理,所以一切都应该是好的,但,没有。 模型场 class Guide(models.Model): image = models.ImageField(upload_to='users/%Y/%m/%d/', blank=True) 设置.py STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = "/static/" MEDIA_URL = '/trips
class Guide(models.Model):
image = models.ImageField(upload_to='users/%Y/%m/%d/', blank=True)
设置.py
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = "/static/"
MEDIA_URL = '/trips/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'trips/media/')
项目树
模板
{% if item.image%}
<img src="{{item.image.url}}" alt="" style="max-height:300px">
{%else%}
<img src="{%static 'avatar_sample.png' %}" id="uploaded_image" class="img-responsive img-circle" />
{%endif%}
{%if item.image%}
{%else%}
{%endif%}
确保在URL.py中导入这些设置
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)