2017-09-27 8 views
0

このサイトはDigital Oceanで公開されています。私は最終的にそれが正常に動作するようになったが、CSSはサイトでは動作しませんか?ここに私がセットアップしたものがあります。エラーはありません。ちょうどCSSが動作しません。DjangoのライブサイトでCSSが動作しません

私は私のsettings.pyでこれを持っている:ここでは

STATIC_URL = '/static/' 
STATIC_ROOT = '/static/' 
STATIC_DIR = os.path.join(BASE_DIR,'static') 

STATICFILES_DIRS = [ 
    STATIC_DIR, 
] 

は私のプロジェクトのurls.pyです:

from django.conf.urls import url 
from django.contrib import admin 
from django.conf.urls import include 
from blog import views 
from users import views 
from feed import views 
from django.conf import settings 
from django.conf.urls.static import static 

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^$',views.HomeView.as_view(),name='index'), 
    url(r'^user/',include('users.urls',namespace='users')), 
    url(r'^feed/',include('feed.urls',namespace='feed')), 
    url(r'^blog/',include('blog.urls',namespace='blog')), 
    url(r'^accounts/', include('allauth.urls')), 
] 

ファイル構造:

- django_project 
    - /allauth/ 
    - /blog/ 
    - /django_project/ 
    - /feed/ 
    - manage.py 
    - /media/ 
    - req.txt 
    - /static/ 
     - /css/ 
    - /templates/ 
    - /users/ 
    - gunicorn.socket 

私はpython manage.py collect static

を実行しました

ここにNginxの設定があります:

upstream app_server { 
    server unix:/home/django/gunicorn.socket 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/django_project/django_project/media; 
    } 

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

    # Proxy the static assests for the Django Admin panel 


    location/{ 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header Host $host; 
      proxy_redirect off; 
      proxy_buffering off; 

      proxy_pass http://app_server; 
    } 

} 
+0

しますか? –

+0

NginxとGunicornのデジタルオーシャン – Garrett

+0

私はnginxについて考えていませんが、djangoではなくサーバーからフロントエンドにメディアと静的ファイルを提供する必要があります。これが役立つかもしれないことを確認してくださいhttps://serverfault.com/questions/370525/nginxdjango-serving-static-files –

答えて

関連する問題