我尝试在setuptools期间实现Compass编译build,但是下面的代码在显式build命令期间运行编译,并且不会在运行期间运行install.
#!/usr/bin/env python
import os
import setuptools
from distutils.command.build import build
SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
class BuildCSS(setuptools.Command):
description = 'build CSS from SCSS'
user_options = []
def initialize_options(self):
pass
def run(self):
os.chdir(os.path.join(SETUP_DIR, 'django_project_dir', 'compass_project_dir'))
import platform
if 'Windows' == platform.system():
command = 'compass.bat compile'
else:
command = 'compass compile'
import subprocess
try:
subprocess.check_call(command.split())
except (subprocess.CalledProcessError, OSError):
print 'ERROR: problems with compiling Sass. Is Compass installed?'
raise SystemExit
os.chdir(SETUP_DIR)
def finalize_options(self):
pass
class Build(build):
sub_commands = …Run Code Online (Sandbox Code Playgroud) 我想使用 Vuetify 的 CSS 类作为混合。为此,我正在使用@extendsStylus 指令。在MyComponent.vue:
<style scoped lang="styl">
.title {
@extends .display-3;
}
</style>
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我没有在每个组件的样式中引入 Vuetify。为了完成这项工作,我将 webpack 配置为在我的应用程序的每个 Stylus 块中加载 Vuetify 的 Stylus 样式。在webpack.config.js:
module.exports = {
/* ... */
plugins: [
/* ... */
new webpack.LoaderOptionsPlugin({
options: {
stylus: {
import: path.join(
__dirname,
'node_modules/vuetify/src/stylus/main.styl',
),
},
},
}),
],
};
Run Code Online (Sandbox Code Playgroud)
但是 Vuetify 的文档说清楚:
不要在组件内导入 main.styl。这将导致性能问题并大大减慢热模块重新加载。
看起来我通过这种方式配置 webpack 违反了这个规则。在任何组件上应用每个更改现在大约需要五秒钟。我认为这是因为 Vuetify 正在每个组件中重建。
有没有一种方法可以将 Vuetify 的 Stylus 样式用作 mixin,而无需在每个组件上重建 Vuetify?
我的setup.py文件中 有两个自定义命令:create_tables和drop_tables:
class create_tables(command):
description = 'create DB tables'
user_options = [
('database=', 'd', 'which database configuration use'),
('reset', 'r', 'reset all data previously'),
]
def initialize_options(self):
command.initialize_options(self)
self.reset = False
def run(self):
if self.reset:
self.run_command('drop_tables')
else:
command.run(self)
from vk_relations import models
models.create_tables()
print 'Tables were created successfully'
class drop_tables(command):
description = 'drop all created DB tables'
user_options = [
('database=', 'd', 'which database configuration use'),
]
def run(self):
command.run(self)
answer = raw_input('Are you sure …Run Code Online (Sandbox Code Playgroud) 可能有人提供了通过django-tastypie和骨干关系来运行django.db模型实例的多对多字段的示例吗?现在可以使用中间模型了.
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=42)
class Book(models.Model):
authors = models.ManyToManyField(Author, related_name='books', through='Authorship')
title = models.CharField(max_length=42)
class Authorship(models.Model):
author = models.ForeignKey(Author)
book = models.ForeignKey(Book)
Run Code Online (Sandbox Code Playgroud)
以下是tastypie资源的配置:
from tastypie import fields, resources
class AuthorResource(resources.NamespacedModelResource):
books = fields.ToManyField('library.api.resources.AuthorshipResource', 'books')
class Meta:
resource_name = 'author'
queryset = models.Author.objects.all()
class BookResource(resources.NamespacedModelResource):
authors = fields.ToManyField('library.api.resources.AuthorshipResource', 'authors')
class Meta:
resource_name = 'book'
queryset = models.Book.objects.all()
class AuthorshipResource(resources.NamespacedModelResource):
author = fields.ToOneField('library.api.resources.AuthorResource', 'author')
book = fields.ToOneField('.api.resources.BookResource', 'book')
class Meta:
resource_name = 'authorship'
queryset = models.Authorship.objects.all() …Run Code Online (Sandbox Code Playgroud) distutils ×2
python ×2
setuptools ×2
many-to-many ×1
stylus ×1
tastypie ×1
vue.js ×1
vuetify.js ×1
webpack ×1