2014-11-01 76 views
0

我只是使用Heroku製作我的網站,並且我的媒體圖像被破壞,出現了一個奇怪的問題。 這是我在Heroku上的網站結構。我的django製作網站上的圖像破碎。爲什麼?

-- app 
    -- manage.py 
    -- mysite 
     -- settings 
     -- __init__.py 
     -- base.py 
     -- production.py 
    -- static 
     -- media 
      -- product 
      -- images 
       -- 
     -- static_dirs 
     -- static_root 

在我的應用程序/ mysite的/設置/ 初始化的.py

from .base import * 
try: 
    from .local import * 
    live = False 
except: 
    live = True 
if live: 
    from .production import * 

,並在我的base.py

import os 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 
STATIC_URL = '/static/' 
MEDIA_URL = '/media/'  
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')  
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root') 
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static', 'static_dirs'), 
)  
TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates'), 
)  

,並在我的production.py,我註釋爲下面。

# Static asset configuration 
# import os 
# BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
# STATIC_ROOT = 'staticfiles' 
# STATIC_URL = '/static/'  
# STATICFILES_DIRS = (
# os.path.join(BASE_DIR, 'static'), 
#) 

最後,我跑了服務器,我的網頁上仍然顯示圖像殘缺。 當我通過「google檢查元素」仔細查看圖像時,我仍然可以看到如下所示的正確路徑。

<img class="img-responsive" src="/media/products/images/aws.png"> 

但是,當我看到我的/靜態/媒體/產品/圖像/文件夾,有發展statge只創建,我不能只是在生產現場創建圖像的圖像。 (aws.png)

作爲django開發的初學者,即使經過幾個小時的谷歌搜索,也很難找到答案。

請讓我睡&謝謝永遠。

+0

在上面的目錄列表中(在問題開始時),您拼寫錯誤的「媒體」。這是問題,還是隻是在您的文章中的錯誤? – trnelson 2014-11-01 14:41:58

+0

哦,這只是我的錯誤,我已經修好了。 – 2014-11-01 14:44:37

回答

0

您需要在生產框上運行collectstatic。

+0

我已經做到了。 – 2014-11-01 18:06:42