3

This site is live and hosted with Digital Ocean. I finally got it to work properly, however the css won't work for the site? Here's what I have setup, there are no errors, just the css won't work.

I have this in my settings.py:

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

STATICFILES_DIRS = [
    STATIC_DIR,
]

Here are my project 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')),
]

File structure:

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

I have run python manage.py collect static

Here is Nginx config:

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

}
Garrett
  • 149
  • 5

1 Answers1

2

It was an Nginx issue. In my Jnginx config file I had the wrong path to the static files

So I had: /home/django/django_project/django_project/static/

But I needed this: /home/django/django_project/static/

Garrett
  • 149
  • 5