0

我已经在 DigitalOcean.com 上部署了我的 Django 项目。我已经设置了静态文件夹并运行python manage.py collectstatic它正常工作。唯一的问题是我在管理页面中看不到全选复选框。

这是在我的本地 Django 项目中:

在此处输入图像描述

这是在部署的项目中:

在此处输入图像描述

我无法弄清楚问题出在哪里。你知道吗?

我正在附加settings.py已部署的项目:

import os

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


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

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

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

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [


    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_app',
    'django.contrib.admin',
    'django_tables2',
    'import_export',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'drevo.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'drevo.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME':'/home/django/drevo/db.sqlite3',
        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'pwd'

ADMIN_EMAIL = 'email@gmail.com'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

VARS_MODULE_PATH = 'main_app.global_variables.py'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_ROOT = '/home/django/drevo/static/'
STATIC_URL = '/static/'
4

2 回答 2

2

我有同样的问题并修复它备份我的静态文件夹中的所有数据,清空它并再次执行:

python manage.py collectstatic

我发现这是因为我之前安装的应用程序(django-grappelli)的静态文件。Django 试图将所需的文件移动到目标 /static/ 文件夹,但由于 django-grapelli 创建了相同的文件,它只是忽略了它们并且没有移动它们。例子:

Found another file with the destination path 'admin/css/dashboard.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.

清空文件夹,我强制命令将所有内容重新复制到那里,之后一切正常。

于 2017-04-16T16:04:39.953 回答
0

我只是面临同样的问题(至少相同的效果)。事实证明(我认为)是一个缓存问题,无论是在 nginx 上还是在客户端浏览器上:

我的生产服务器使用 Debian jessie、nginx、gunicorn、Django 1.10.2 + SSL。

要测试您是否有缓存问题,请运行(如果您的产品服务器允许这样做)

./manage.py runserver 0.0.0.0:8000

(或您可以访问的任何其他端口)在您的生产服务器上一小会儿。并在那里测试复选框是否存在。如果是,那么只需重新启动服务器服务并强制刷新浏览器缓存几次(在我知道的大多数浏览器上按 shift+单击刷新箭头)。

于 2017-01-15T22:23:46.083 回答