python - Static Files not being displayed in Production -


edited show updated configuration

no static files being shown in production. files showing correctly in development

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 

files being called in applications <link href="{% static "css/portfolio-item.css" %}" rel="stylesheet">

using nginx , gunicorn.

nginx config:

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;  } 

running python manage.py collectstatic reports files copied still not being displayed.

deployment handled fabric

from __future__ import with_statement fabric.api import * fabric.contrib.console import confirm  env.hosts = []  print "here 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/'     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() 

first of all, seems me edited staticfiles_dirs points wrong folder, since have /static/ folder, not /staticfiles/. should originally:

staticfiles_dirs = (     os.path.join(base_dir, 'static'), ) 

second, static_root should point static folder served webserver in pro (but preferably not in project folder). in case:

static_root="/opt/soundshelter/soundshelter/soundshelter/static/" 

i place static folder near project 1 , use dynamic static_root instead of hardcoding:

base_dir = os.path.abspath(os.path.dirname(__file__)) #this alow collect static files in /opt/soundshelter/soundshelter/staticfiles/static static_root = os.path.join(os.path.dirname(base_dir), 'staticfiles/static') 

now should collectstatic , collect static files in static_root directory.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -