我在Digital Ocean中使用ubuntu操作系统,当我部署我的django / Python应用程序时,只有当我提到 Debug=True
时,它才有用。
我尝试了 ALLOWEDHOSTS = ['*'] & ALLOWEDHOSTS = ['127.0.0.1']
。我也尝试了为Droplet分配的IP,即使这样它只会引发错误。
除此之外,当Debug为True
时,当我启动服务器并导航到浏览器时,我发现它没有在静态文件夹中加载css / js文件。
非常感谢任何帮助。
我看到有些问题与此类似,但没有一个问题得到妥善回答。
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/supchang/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/ssupchang/static;
}
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;
}
}
Gunicorn.conf
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectadly trigger a respawn
respawn
setuid django
setgid django
chdir /home/django
exec gunicorn \
--name=supchang \
--pythonpath=ssupchang \
--bind=127.0.0.1:9000 \
--config /etc/gunicorn.d/gunicorn.py \
ssupchang.wsgi:application
Logs
2014/10/29 00:32:23 [error] 14812#0: *68 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121448 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14812#0: *68 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121449 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14812#0: *78 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121450 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14812#0: *78 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121451 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14812#0: *78 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121452 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14811#0: *38 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121453 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:23 [error] 14811#0: *38 open() "/home/django/ssupchang/static/assets/js/trainee_app_get_subcategories_results.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_get_subcategories_results.js?_=1414556121454 HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14811#0: *38 open() "/home/django/ssupchang/static/assets/css/master.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/master.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14812#0: *78 open() "/home/django/ssupchang/static/assets/css/normalize.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/normalize.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14811#0: *48 open() "/home/django/ssupchang/static/assets/css/trainee_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/trainee_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14812#0: *68 open() "/home/django/ssupchang/static/assets/css/tutor_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/tutor_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14812#0: *79 open() "/home/django/ssupchang/static/django_summernote/django_summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/django_summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14812#0: *82 open() "/home/django/ssupchang/static/django_summernote/summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14811#0: *38 open() "/home/django/ssupchang/static/assets/js/trainee_app_browse_by_category.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_browse_by_category.js HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:32:27 [error] 14812#0: *78 open() "/home/django/ssupchang/static/assets/js/trainee_app_accounts.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_accounts.js HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *83 open() "/home/django/ssupchang/static/assets/css/master.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/master.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *85 open() "/home/django/ssupchang/static/assets/css/normalize.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/normalize.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *86 open() "/home/django/ssupchang/static/assets/css/tutor_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/tutor_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *87 open() "/home/django/ssupchang/static/assets/css/trainee_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/trainee_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *88 open() "/home/django/ssupchang/static/django_summernote/django_summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/django_summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *89 open() "/home/django/ssupchang/static/django_summernote/summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *83 open() "/home/django/ssupchang/static/assets/js/trainee_app_browse_by_category.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_browse_by_category.js HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:35 [error] 14812#0: *85 open() "/home/django/ssupchang/static/assets/js/trainee_app_accounts.js" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/js/trainee_app_accounts.js HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:40 [error] 14812#0: *90 open() "/home/django/ssupchang/static/assets/css/master.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/master.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:41 [error] 14812#0: *92 open() "/home/django/ssupchang/static/assets/css/trainee_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/trainee_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:41 [error] 14812#0: *91 open() "/home/django/ssupchang/static/assets/css/normalize.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/normalize.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:41 [error] 14812#0: *93 open() "/home/django/ssupchang/static/django_summernote/django_summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/django_summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:41 [error] 14812#0: *94 open() "/home/django/ssupchang/static/assets/css/tutor_default.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/tutor_default.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:34:41 [error] 14812#0: *95 open() "/home/django/ssupchang/static/django_summernote/summernote.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/django_summernote/summernote.css HTTP/1.1", host: "128.199.240.28", referrer: "http://128.199.240.28/"
2014/10/29 00:45:07 [error] 14941#0: *29 open() "/home/django/ssupchang/static/assets/css/master.css" failed (2: No such file or directory), client: 49.205.81.48, server: _, request: "GET /static/assets/css/master.css HTTP/1.1", host: "128.199.240.28"
答案 0 :(得分:1)
您正在设置ALLOWEDHOSTS
,这是不正确的。
正确的名称是ALLOWED_HOSTS
,如the documentation中所示。
答案 1 :(得分:0)
尝试ALLOWED_HOSTS = ['localhost']或ALLOWED_HOSTS = ['localhost','127.0.0.1']
答案 2 :(得分:0)
您允许的主机应该是您的IP或类似此格式的域名
ALLOWED_HOSTS =['.domainname',]