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

2024-03-29 15:10:07 发布

您现在位置:Python中文网/ 问答频道 /正文

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

有什么想法吗??在

下面是我的设置.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配置:

^{pr2}$

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/"

Tags: djangoprojectuiadminrequestcustomjsstatic
2条回答

运行python manage.py collectstatic
这将收集要由web服务器切断的静态文件。在

Deploying static files的正式文档。在

更新

# 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。管理css将由collectstatic收集到/static/admin目录中。重新加载nginx。在

同时检查Nginx日志。在

删除:

# 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为应用程序查找静态文件的方式,并破坏了Grappelli。在

记住以后要重新加载nginx。在

相关问题 更多 >