gpt4 book ai didi

python - Django 找不到静态文件

转载 作者:行者123 更新时间:2023-11-28 17:26:11 27 4
gpt4 key购买 nike

我正在尝试在 Digital Ocean 上部署我的 Django 项目.我选择了 Django App droplet 以使其更简单。

然后我简单地安装了需求,将它们的 django_project 替换到我的项目中。

问题是静态文件(至少 css)根本不起作用。我可以看到网络,但看不到 css

设置.py:

STATIC_ROOT = '/home/django/SolutionsForLanguages_2/SolutionsForLanguagesApp/static'
STATIC_URL = '/static/'

我已遵循本教程 One-Click Django - DigitalOcean

是否python manage.py collectstatic我已经尝试重启 gunicorn

nginx/可用站点/django:

upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

client_max_body_size 4G;
server_name _;

keepalive_timeout 5;

# Your Django project's media files - amend as required
location /media {
alias /home/django/SolutionsForLanguages_2/SolutionsForLanguagesApp/media;
}

# your Django project's static files - amend as required
location /static {
alias /home/django/SolutionsForLanguages_2/SolutionsForLanguagesApp/static;
}

# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;
}

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}

编辑:

CSS 适用于 Django-Admin 页面

重要修改

我检查了 nginx 日志,它似乎试图在错误的路径中找到这些文件。它正在他们的默认项目路径中搜索。

2016/08/09 06:31:29 [error] 998#0: *140 open() "/home/django/django_project/django_project/static/css/bootstrap.min.css" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/css/bootstrap.min.css HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:29 [error] 998#0: *142 open() "/home/django/django_project/django_project/static/css/jumbotron.css" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/css/jumbotron.css HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:29 [error] 998#0: *140 open() "/home/django/django_project/django_project/static/css/dropdown.css" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/css/dropdown.css HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:29 [error] 998#0: *143 open() "/home/django/django_project/django_project/static/css/bootstrap-theme.min.css" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/css/bootstrap-theme.min.css HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *140 open() "/home/django/django_project/django_project/static/img/hourglass.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/hourglass.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *142 open() "/home/django/django_project/django_project/static/img/value.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/value.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *143 open() "/home/django/django_project/django_project/static/img/people.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/people.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *144 open() "/home/django/django_project/django_project/static/img/howitworks.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/howitworks.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *140 open() "/home/django/django_project/django_project/static/img/languages.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/languages.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *142 open() "/home/django/django_project/django_project/static/img/logos.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/logos.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *143 open() "/home/django/django_project/django_project/static/img/pricing.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/pricing.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *144 open() "/home/django/django_project/django_project/static/img/fcb.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/fcb.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *140 open() "/home/django/django_project/django_project/static/img/twitter.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/twitter.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *142 open() "/home/django/django_project/django_project/static/img/linkedin.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/linkedin.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"
2016/08/09 06:31:30 [error] 998#0: *145 open() "/home/django/django_project/django_project/static/img/helpful.png" failed (2: No such file or directory), client: 89.103.231.4, server: _, request: "GET /static/img/helpful.png HTTP/1.1", host: "37.139.20.125", referrer: "http://37.139.20.125/"

最佳答案

如果你的日志文件显示 nginx 正在寻找文件到服务器但是从错误的位置那么这是因为你的 nginx 文件自上次更改以来没有更新。

Reload your nginx configuration它应该开始正确地提供文件。

关于python - Django 找不到静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38847647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com