0
这个网站是生活和数字海洋主办。我终于得到它正常工作,但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;
}
}
哪一个是你在活动网站使用的服务器? –
Nginx和Gunicorn的数字海洋 – Garrett
我不知道nginx,但你应该服务于前端服务器的媒体和静态文件不django。检查这可能是它可以帮助https://serverfault.com/questions/370525/nginxdjango-serving-static-files –