我正在使用Django-Bower测试Foundation 5的SASS实现。我对Bower的想法是陌生的,并且对如何使此设置正常工作感到有些困惑。
我已经安装了django-bower并将其配置为可以正常运行。将基础添加到Bower应用程序配置并运行后,manage.py bower_install
我可以看到基础文件确实已正确安装。我还可以使用static标签将JS加载到模板中而不会出现问题,所以我感觉到了一半。
我的问题是关于如何实际使用随我的自定义SASS文件安装的bower的基础文件,以及将这些SASS文件编译为CSS的最佳方法。我知道我应该能够将基础包括在我的SASS中,@include "foundation"
但是我对如何获取SASS文件以“查看” components / bower_components / foundation / sass中的基础文件以及如何进行设置一无所知将css放入正确的静态文件的编译。
更新:PyCharm有一个选项可以查看sass文件并进行编译,因此我现在可以选择编译文件,但是当我尝试导入基础时,我得到了 error blog3.sass (Line 1: File to import not found or unreadable: foundation.
供参考,这是我的文件结构:
├── blog3
│ └── __pycache__
├── components
│ └── bower_components
│ ├── foundation
│ │ ├── css
│ │ ├── js
│ │ │ ├── foundation
│ │ │ └── vendor
│ │ └── scss
│ │ └── foundation
│ │ └── components
│ ├── jquery
│ └── modernizr
│ ├── feature-detects
│ ├── media
│ └── test
│ ├── caniuse_files
│ ├── js
│ │ └── lib
│ └── qunit
└── interface
├── migrations
│ └── __pycache__
├── __pycache__
├── sass
└── templates
└── interface
这是我的settings.py
"""
Django settings for blog3 project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/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/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '...'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'annoying',
'django_extensions',
'djangobower',
'interface',
)
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',
)
ROOT_URLCONF = 'blog3.urls'
WSGI_APPLICATION = 'blog3.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/dev/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/dev/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'djangobower.finders.BowerFinder',
)
BOWER_COMPONENTS_ROOT = os.path.join(BASE_DIR, "components")
BOWER_INSTALLED_APPS = (
'jquery',
'foundation',
)
这是使用django-compressor的“如何编译scss文件”的示例:
appName / static / scss / app.scss:
@import "../../../components/bower_components/foundation/scss/foundation";
@import "compass";
/* other stuff*/
settings.py:
STATICFILES_FINDERS = (
.....
'compressor.finders.CompressorFinder',
)
COMPRESS_PRECOMPILERS = (
('text/x-sass', 'sass --compass "{infile}" "{outfile}"'),
('text/x-scss', 'sass --scss --compass "{infile}" "{outfile}"'),
)
COMPRESS_URL = '/static/'
template.html:
{% load static %}
{% load compress %}
<head>
{% compress css %}
<link href="{% static 'scss/app.scss' %}" media="screen, projection" rel="stylesheet" type="text/x-scss" />
{% endcompress %}
</head>
希望对您有帮助。
编辑
也许这是一个更好的配置,可以在没有亲戚路径的情况下使用@import。-I
arg:
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
BOWER_COMPONENTS_ROOT = os.path.join(PROJECT_PATH, "../components/")
COMPRESS_PRECOMPILERS = (
('text/x-sass', 'sass --compass "{infile}" "{outfile}"'),
('text/x-scss', 'sass --scss --compass -I "%s/bower_components/foundation/scss" "{infile}" "{outfile}"' % BOWER_COMPONENTS_ROOT),
)
现在是app.scss:
@import "foundation";
@import "compass";
最近我很欣赏pycharm watcher
安装django-bower
从pycharm首选项添加SCSS Watcher
在监视程序的编辑中,将“参数”字段设置为:
--compass -I“ / $ ProjectFileDir $ / components / bower_components / foundation / scss” --no-cache --update $ FileName $:$ FileNameWithoutExtension $ .css
因此,在scss文件中:
@import "foundation";
@import "compass";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句