2017-07-28 47 views
2

我試圖從django管理面板上傳圖像,然後進行了以下更改。但是,當我嘗試在wine_list頁面和review_list中加載圖像時出現此錯誤。圖像被存儲在媒體然而,它不是正被顯示:從Django的管理面板顯示圖像時出錯

Page not found (404) 
Request Method: GET 
Request URL: http://127.0.0.1:8000/static/media/download_1.jpg 
Raised by: django.views.static.serve 
'media\download_1.jpg' could not be found 

這裏是wine_list一個代碼

{% extends 'base.html' %} 

{% block title %} 
<h2>Wine list</h2> 
{% endblock %} 

{% block content %} 
{% if wine_list %} 
{% load static %} 

<div> 
    {% for wine in wine_list %} 
    <div><ul> 
    <li> 
     <h4><a href="{% url 'reviews:wine_detail' wine.id %}"> 
     {{ wine.name}}</a> 
     <br> 
     <a><img src="{% static wine.images.url %}" height="200"></a> 
     <br> 
     <br> 

這裏是用於review_list圖像部分的代碼:

{% extends 'base.html' %} 

{% block title %} 
<h2>Latest reviews</h2> 
{% load static %} 
{% endblock %} 

{% block content %} 
{% if latest_review_list %} 
<div class="row"> 
    {% for review in latest_review_list %} 
    <div class="col-xs-6 col-lg-4"> 




     <h4><a href="{% url 'reviews:review_detail' review.id %}"> 
     {{ review.wine.name }} 

     </a></h4> 
<br> 
     <a><img src="{% static review.wine.images.url %}" height="200"></a>  

urls.py爲winerama文件夾

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

urlpatterns = [ 
    url(r'^reviews/', include('reviews.urls', namespace="reviews")), 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^accounts/', include('registration.backends.simple.urls')), 
    url(r'^accounts/', include('django.contrib.auth.urls', namespace="auth")), 

] 

if settings.DEBUG: 
    urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT) 
    urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) 

回答

1

檢查您的設置文件是否你設置爲靜態圖像路徑:

STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static/') 

同時檢查圖像文件的權限也。其可從任何地方訪問。

1

指定:{{review.wine.images.url}}

<a><img src="{{ review.wine.images.url }}" height="200"></a> 
+0

我校正的語句仍然沒有被顯示的圖像 – adhistac