更改占位符 django cms 的背景颜色

Posted

技术标签:

【中文标题】更改占位符 django cms 的背景颜色【英文标题】:change background color of placeholder django cms 【发布时间】:2017-03-14 02:45:16 【问题描述】:

我希望用户能够更改占位符的颜色。

我尝试安装 djangocms-css-background。 我把这些步骤搁置了https://pypi.python.org/pypi/djangocms-css-background/1.0.4

起初我遇到错误:“找不到模块 djangocms-css-background”当我运行 python manage migrate.

不知何故,我修复了一个错误。但我坚持这个

djangocms-css-background.CssBackground.cmsplugin_ptr: (fields.E306) The name 'djangocms-css-background_cssbackground' is invalid related_name for field CssBackground.cmsplugin_ptr
    HINT: Related name must be a valid Python identifier or end with a '+'

settings.py

import os
gettext = lambda s: s
DATA_DIR = os.path.dirname(os.path.dirname(__file__))
"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 1.8.15.

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

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

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

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.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '6!we3efe11p$%8x#r3y_)pioj5&-%%$g5ezmu2m_dm(^_f^2m8'

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

ALLOWED_HOSTS = []


# Application definition





ROOT_URLCONF = 'mysite.urls'



WSGI_APPLICATION = 'mysite.wsgi.application'


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




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

LANGUAGE_CODE = 'en'

TIME_ZONE = 'Europe/Ljubljana'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, javascript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'static')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'mysite', 'static'),
)
SITE_ID = 1


TEMPLATES = [
    
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'mysite', 'templates'),],
        'OPTIONS': 
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.i18n',
    'django.core.context_processors.debug',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.csrf',
    'django.core.context_processors.tz',
    'sekizai.context_processors.sekizai',
    'django.core.context_processors.static',
    'cms.context_processors.cms_settings'
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader'
            ],
        ,
    ,
]


MIDDLEWARE_CLASSES = (
    'cms.middleware.utils.ApphookReloadMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware'
)

INSTALLED_APPS = (
    'djangocms_admin_style',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'cms',
    'menus',
    'sekizai',
    'treebeard',
    'djangocms_text_ckeditor',
    'filer',
    'easy_thumbnails',
    'djangocms_column',
    'djangocms_link',
    'cmsplugin_filer_file',
    'cmsplugin_filer_folder',
    'cmsplugin_filer_image',
    'cmsplugin_filer_utils',
    'djangocms_style',
    'djangocms_snippet',
    'djangocms_googlemap',
    'djangocms_video',
    'mysite',
    'djangocms-css-background'

)

LANGUAGES = (
    ## Customize this
    ('en', gettext('en')),
)

CMS_LANGUAGES = 
    ## Customize this
    'default': 
        'public': True,
        'hide_untranslated': False,
        'redirect_on_fallback': True,
    ,
    1: [
        
            'public': True,
            'code': 'en',
            'hide_untranslated': False,
            'name': gettext('en'),
            'redirect_on_fallback': True,
        ,
    ],


CMS_TEMPLATES = (
    ## Customize this
    ('fullwidth.html', 'Fullwidth'),
    ('sidebar_left.html', 'Sidebar Left'),
    ('sidebar_right.html', 'Sidebar Right'),
    ('template_1.html', 'Template One'),
    ('template_2.html', 'Template Two')
)

CMS_PERMISSION = True

CMS_PLACEHOLDER_CONF = 

DATABASES = 
    'default': 
        'CONN_MAX_AGE': 0,
        'ENGINE': 'django.db.backends.sqlite3',
        'HOST': 'localhost',
        'NAME': 'project.db',
        'PASSWORD': '',
        'PORT': '',
        'USER': ''
    


MIGRATION_MODULES = 



THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters'
)

我试过了

python manage.py makemigrations djangocms-css-background

我得到同样的错误

我在自述文件中看到了带 + 的语法。无论我把 + 放在哪里,我都会收到错误“invalid sintax”。

我正在使用 django 1.10,python 2.7

如果有人对此有任何建议或其他想法。 感谢您的帮助

【问题讨论】:

【参考方案1】:

创建djangocms-css-background 包的人对应用程序的命名很糟糕,因为 python 不喜欢文件名包含连字符 (-)。他们应该将包中的***目录命名为djangocms_css_background

存储库和 pypi 包可以包含连字符,它只是应用程序目录。

这就是你遇到问题的原因。

该软件包已折旧且不再维护,并且快速浏览会出现一些问题。

您可以分叉软件包,解决问题,然后安装您的软件包版本。

但是您到底想做什么,因为我对这个问题并不太清楚。如果您希望能够更改容器的背景颜色(就像这个应用程序允许的那样),重新创建非常简单。我只是不是 100% 你所说的“占位符的背景颜色”。

如果您提供更多信息,我可能会为您提供进一步的帮助。

【讨论】:

以上是关于更改占位符 django cms 的背景颜色的主要内容,如果未能解决你的问题,请参考以下文章

text 使用此输入占位符SCSS Mixin更改占位符属性的颜色。添加背景颜色或只更改文本颜色

更改自定义文本字段背景颜色和文本颜色IOS Swift

Django-CMS - 全球占位符?

django cms 占位符不在结构视图中

cms 之外的 Django CMS 简单占位符

截断 Django CMS 占位符