使用更少的代码在django-oscar中自定义CSS文件

时间:2018-10-08 15:21:07

标签: css django django-oscar

我对django oscar还是陌生的,只对网站前端有基本了解。

我想更改django oscar中的styles.css。我试图直接在styles.css中进行更改,但是以某种方式刷新本地主机时,它没有检测到任何更改(默认CSS)。

我尝试更改了less文件,安装了npm,减少了安装并将设置更改为OSCAR_USE_LESS = True。本地主机甚至根本不渲染css文件,仅渲染模板。

当我在根目录中写入命令make css时,即使我安装的次数较少,也会发生以下错误。

make: *** No rule to make target `css'.  Stop.

所以我真的不知道我的设置或已安装的应用程序出了什么问题。

设置是

import os
import oscar

# Path helper - going into /Users/dion/Dev/dioncoffee/x
location = lambda x: os.path.join(
    os.path.dirname(os.path.dirname(os.path.realpath(__file__))), x)

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=%*t%wzzw^hs5l2o@oq2ae-*&wde0bko4!hxl%=uqb$!5po$tt'

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

ALLOWED_HOSTS = []


# Application definition

from oscar import get_core_apps

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    'django_extensions',

    'compressor',
    #'apps.gateway',     # For allowing dashboard access
    'widget_tweaks',
] + get_core_apps(
      ['apps.promotions']
      )

SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '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',
    'oscar.apps.basket.middleware.BasketMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
]

ROOT_URLCONF = 'dioncoffee.urls'

from oscar import OSCAR_MAIN_TEMPLATE_DIR

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [            
            location('dioncoffee/templates'),
            oscar.OSCAR_MAIN_TEMPLATE_DIR,
            ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.contrib.messages.context_processors.messages',

                'oscar.apps.search.context_processors.search_form',
                'oscar.apps.promotions.context_processors.promotions',
                'oscar.apps.checkout.context_processors.checkout',
                'oscar.apps.customer.notifications.context_processors.notifications',
                'oscar.core.context_processors.metadata',
            ],
        },
    },
]

WSGI_APPLICATION = 'dioncoffee.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'dioncoffee',
        'USER': 'dion',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.1/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',
    },
]

AUTHENTICATION_BACKENDS = (
    'oscar.apps.customer.auth_backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
    },
}

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

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = location("public/media")

STATIC_ROOT = location('public/static')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'

STATIC_URL = '/static/'

# /Users/dion/Dev/dioncoffee/static/
STATICFILES_DIRS = (
    location('static'),
)

from oscar.defaults import *

OSCAR_DEFAULT_CURRENCY = 'EUR'

OSCAR_CURRENCY_FORMAT = {
    'USD': {
        'currency_digits': False,
        'format_type': "accounting",
    },
    'EUR': {
        'format': u'#,##0\xa0¤',
    }
}

USE_LESS = True
COMPRESS_ENABLED = False
COMPRESS_PRECOMPILERS = (
('text/less', 'lessc {infile} {outfile}'),
)
COMPRESS_OFFLINE_CONTEXT = {
'STATIC_URL': 'STATIC_URL',
'use_less': USE_LESS,
}

我的目录文件

enter image description here

我正在使用python 3.6.5。

1 个答案:

答案 0 :(得分:1)

make css仅用于Oscar本身的开发-不适用于您的项目。我看不到为什么USE_LESS方法在调试模式下会失败。

也就是说,我认为您最好重写CSS,而不要依赖USE_LESS,后者可能会在将来完全删除,并且仅用于开发。

如果放置在正确的位置,则应该能够覆盖CSS。

如果您的CSS内置在应用程序中,则它需要放入app_dir/static/oscar/css/style.css中,并且您需要在'django.contrib.staticfiles.finders.AppDirectoriesFinder'设置中包含STATICFILES_FINDERS

或者,如果您有一个单独的静态文件目录,则需要在设置中包括'django.contrib.staticfiles.finders.FileSystemFinder',并指定STATICFILES_DIRS来告诉Django该目录在哪里。