編輯以SHOW更新的配置靜態文件未顯示在生產
沒有靜態文件在生產中被顯示。文件被正確地顯示在發展
settings.py
BASE_DIR = os.path.dirname(__file__)
STATIC_ROOT = '/opt/soundshelter/static/'
print "Base Dir: " + BASE_DIR #this returns /opt/soundshelter/soundshelter/soundshelter
print "Static Root: " + STATIC_ROOT #this returns /opt/soundshelter/static/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
) #/opt/soundshelter/soundshelter/soundshelter/static
文件被稱爲應用程序與 <link href="{% static "css/portfolio-item.css" %}" rel="stylesheet">
使用Nginx的和Gunicorn。
Nginx的配置:
server {
server_name 46.101.56.50;
access_log yes;
location /static {
autoindex on;
alias /opt/soundshelter/static/;
}
location/{
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
# error_log /opt/soundshelter/soundshelter/soundshelter/nginx-error.log;
}
運行python manage.py collectstatic
報告文件已成功複製,但仍然沒有顯示。
部署由面料
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
env.hosts = []
print "Here we go..."
def commit():
local("git add . && git commit")
def push():
local("git push origin master")
def prepare_deploy():
commit()
push()
def deploy():
code_dir = '/opt/soundshelter/soundshelter/'
with cd(code_dir):
run("git pull")
run("python manage.py collectstatic -v0 --noinput")
run("service nginx restart")
run("ps aux |grep gunicorn |xargs kill -HUP")
run("gunicorn -b PROD_IP soundshelter.wsgi:application")
commit()
push()
deploy()
你如何提供這些文件開始?使用'staticfiles'應用程序?它是它的默認配置,它只能在DEBUG模式下工作。您可能需要[從文檔開始](https://docs.djangoproject.com/en/1.8/howto/static-files/)。 –
@Franco不,你沒有。關於你如何提供這些文件,你一點也沒有說。 –
誤讀了評論,現在更新了問題 – Franco