当前位置: 首页 > 知识库问答 >
问题:

缺少Django Grappelli样式[数字海洋设置]

慕光赫
2023-03-14

我部署了一个安装了Django admin的数字海洋水滴。当我安装Django Grappelli并尝试加载管理员时,Django Grappelli中的css和js文件丢失,导致页面显示纯HTML。当我检查元素时,所有必需的图形文件都丢失了,代码为404。

有什么想法吗??

以下是我的ettings.py供参考:

"""
Django settings for django_project project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxx'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['xxxxxxxxxx']


# Application definition

INSTALLED_APPS = (
    'grappelli',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.contrib.auth.context_processors.auth',

)

ROOT_URLCONF = 'django_project.urls'

WSGI_APPLICATION = 'django_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django',
        'USER': 'django',
        'PASSWORD': 'Wxxxxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

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

这是我的NGINX配置:

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

NGINX错误日志:

    2015/05/04 08:52:03 [error] 1056#0: *1060 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1062 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/screen.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/screen.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1063 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/mueller/grid/output.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/mueller/grid/output.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1064 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1065 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1066 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1060 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:03 [error] 1056#0: *1060 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/"
2015/05/04 08:52:09 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/screen.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/screen.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1069 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/mueller/grid/output.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/mueller/grid/output.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1071 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1070 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1072 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:09 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/logout/"
2015/05/04 08:52:12 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1069 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/screen.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/screen.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1071 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/mueller/grid/output.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/mueller/grid/output.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1070 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1072 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1073 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:12 [error] 1056#0: *1067 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1076 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1078 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/screen.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/screen.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1076 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/mueller/grid/output.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/mueller/grid/output.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1080 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1079 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1081 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1076 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1076 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:52:47 [error] 1056#0: *1076 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:09 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:09 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/screen.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/screen.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:09 [error] 1056#0: *1085 open() "/home/django/django_project/django_project/static/grappelli/stylesheets/mueller/grid/output.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/stylesheets/mueller/grid/output.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:09 [error] 1056#0: *1086 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:10 [error] 1056#0: *1088 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:10 [error] 1056#0: *1089 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:10 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/jquery/jquery-1.9.1.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/jquery-1.9.1.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:10 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/js/jquery-ui-1.10.3.custom.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:10 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/js/grappelli.min.js" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/js/grappelli.min.js HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"
2015/05/04 08:57:14 [error] 1056#0: *1083 open() "/home/django/django_project/django_project/static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css" failed (2: No such file or directory), client: 89.241.185.12, server: _, request: "GET /static/grappelli/jquery/ui/css/custom-theme/jquery-ui-1.10.3.custom.min.css HTTP/1.1", host: "178.62.67.237", referrer: "http://178.62.67.237/admin/login/?next=/admin/"

共有2个答案

吴升
2023-03-14

运行python管理。py collectstatic
这将收集要由web服务器断开的静态文件。

用于部署静态文件的正式文档。

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

这似乎是许可问题。删除这个块作为 /static已经设置. admin css将被收集在 /static/admin目录下由Collectstest.重新加载nginx。

还要检查Nginx日志。

郭星文
2023-03-14

删除:

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

它覆盖了Django查找应用程序静态文件的方式,并打破了Grapelli。

之后记得重新加载nginx。

 类似资料:
  • 我遵循这个指南,在Ubuntu(LAMP stack)上为Digital Ocean设置Laravel 5.1。当我尝试通过单击鼠标访问我的Laravel应用程序时,我得到: 我先安装Composer,然后安装Laravel,然后安装目录在我的路径中“这样您的系统就可以找到laravel可执行文件。” : 然后按照这个指南改变我的webroot,这样我就可以像Laravel期望的那样从提供服务:

  • 您可以设置海洋的亮度。亮度的数值范围是 [0, 1] ,默认的亮度数值是0.5: controller.adjustOceanBrightness(0.8);

  • 海洋是3D地球表面表示海洋的特定区域,在Gio地球表面,海洋是最暗的区域。海洋的默认亮度是0.5。 可以通过 configure() API来设置海洋的亮度,具体设置方式如下所示: controller.configure({         brightness: {                 ocean:0.8         } }); 也可以通过 adjustOceanBrightn

  • 我已经向Digital ocean表示歉意,在登台(Heroku服务器)上,应用程序运行良好,但Digitale ocean失败了,错误如下,可能是什么问题:

  • 我在数字海洋水滴上建立了一个Django站点,但是静态文件似乎无法访问。 环顾四周寻找解决方案,我认为问题在于服务器设置(Nginx),但由于这对我来说更为新,我想在弄糟它之前验证一下。 CSS被放置在中,该文件夹不能使用浏览器访问: IPadress/static/css/style。css在css上出现“404未找到”错误 我刚刚找到了Nginx错误日志,其中声明在中查找静态文件,但该日志不存

  • 我尝试了所有方法,但我的文件夹配置文件图片仍然没有出现。他们在网页上看起来像这样。 我在生产我的Django 2.1应用程序,使用数字海洋运行ASGI服务器(因为我使用)。 我的文件夹位于我的根文件夹中(与