jason0401 发表于 2017-12-23 17:05:27

nginx,uwsgi,部署django,静态文件不生效问题

  打开浏览器,然后访问服务器,如果能够正常访问,并且页面链接可以跳转,但是页面却是乱的,那一定是nginx.conf里面的静态文件配置不正确,
  location /static/ {
  #expires 30d;
  #autoindex on;
  #access_log off;
  #add_header Cache-Control private;
  root /root/project/;      
  }
  #比如我的项目在/root/project/,这里面包含manage.py还有很多app,然后我们需要在settings.py文件增加STATIC_ROOT = os.path.join(BASE_DIR, "static"),
  STATICFILES_FINDERS = (
  "django.contrib.staticfiles.finders.FileSystemFinder",
  "django.contrib.staticfiles.finders.AppDirectoriesFinder"
  )
  其他的不改动,然后在服务器中的/root/project/目录新建文件夹static,运行python3 manage.py collectstatic,会将所有app中的static中的静态文件拷贝到当前目录static中,留作nginx使用,收集之后,我们需要重启nginx,然后再启动uwsgi,再访问服务器就可以看到样式了。
页: [1]
查看完整版本: nginx,uwsgi,部署django,静态文件不生效问题