2017-02-22 76 views
1

我正在使用Django框架的網站上工作。我已將項目相關的靜態文件放入名爲our_staticcollectstatic的文件夾static中。下面是我的設置Django靜態文件未找到

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

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, "our_static"), 
] 

base.html文件文件:

​​

這裏our_static文件不會在所有得到讀取。我的style.css位於our_static文件夾中。

編輯: 我使用的是AWS EC2 ubuntu 14.04作爲我的服務器,該網站在本地主機上正常工作,但在AWS ubuntu服務器中無法正常工作。我正在使用Apache2服務器。

更多配置:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
STATICFILES_FINDERS =[ 
'django.contrib.staticfiles.finders.FileSystemFinder', 
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
] 

我的Apache2配置:

Alias /static /home/ubuntu/pythonserver/static 
<Directory /home/ubuntu/pythonserver/static> 
    Require all granted 
</Directory> 

<Directory /home/ubuntu/pythonserver/pythonserver> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
</Directory> 

WSGIDaemonProcess pythonserver python-path=/home/ubuntu/pythonserver python-home=/home/ubuntu/knowmenow/ 
WSGIProcessGroup pythonserver 
WSGIScriptAlias//home/ubuntu/pythonserver/pythonserver/wsgi.py 
+0

這是在本地或服務器上?請添加你的'BASE_DIR'設置。如果在服務器上,你的對應配置是什麼?無論哪種情況,這個顯示的東西都和你呈現的html一樣? 'href =「{%static'style.css'%}」'? – YPCrumble

+0

在本地服務器中工作正常,當我部署到aws服務器(ubuntu)時出現問題。 'BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__))) '是我的'BASE_DIR'。 – Naroju

+0

您使用什麼網絡服務器(例如,NGINX,Apache?) - 請提供配置。當您檢查網站的呈現html時,在瀏覽器中的html中顯示了什麼樣的'href =「{%static'style.css'%}」? – YPCrumble

回答