'use strict';
/*
npm install --save-dev \
gulp \
node-sass \
gulp-sass \
compass-mixins \
bootstrap-sass \
gulp-autoprefixer \
gulp-minify-css \
gulp-sourcemaps
*/
// load plugins
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minify_css = require('gulp-minify-css'),
sourcemaps = require('gulp-sourcemaps'),
path = require('path');
gulp.task('sass', function () {
gulp.src("paths/to/sass/files/**/*.sass")
.pipe(sourcemaps.init())
.pipe(
sass({
includePaths: [],
imagePath: "path/to/images"
})
.on('error', sass.logError))
// https://github.com/ai/browserslist
.pipe(autoprefixer("last 2 version", "> 1%", "Explorer >= 8", {
cascade: true
}))
.pipe(minify_css({compatibility: 'ie8'}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest("paths/to/css_dir"));
});
//watch
gulp.task('live', function () {
//watch .sass files
gulp.watch("paths/to/sass/files/**/*.sass", ['sass']);
});
gulp.task('default', ['live']);
def foo_view(request):
return render(request, 'foo_tpl.html', {'is_error': False})
{% if is_error %}
shit happens
{% endif%}
# urls.py
url(r"^/show-all/(?P<pk>\d+)/", some_view, name='show_all' ),
url(r"^/rozdil/(?P<pk>\d+)/", some_view1, name='rozdil' ),
url(r"^/name-part/(?P<pk>\d+)/", some_view2, name='name_part'),
# models.py
class NamePart(models.Model):
title = models.CharField(max_length=255,verbose_name=" .")
def get_absolute_url(self):
# используй
# https://docs.djangoproject.com/en/1.8/topics/http/urls/#reverse-resolution-of-urls
return reverse('name_part', self.id)
def __unicode__(self):
return u'%s' % (self.title)
class Rozdil(models.Model):
title = models.CharField(max_length=255,verbose_name="Налу")
part_of = models.ForeignKey(NamePart,verbose_name="н")
is_main = models.BooleanField(default=1,verbose_name="Гоний ?")
def get_absolute_url(self):
return reverse('rozdil', self.id)
def __unicode__(self):
return u'%s' % (self.title)
#views.py
def some_view(request):
foo = []
for name_part in NamePart.objects.all():
foo.append({
'name_part': name_part,
'rozdils': Rozdil.objects.filter(part_of=name_part.pk)
})
return render(request, 'template_show_all.html', {'foo': foo})
# template_show_all.html
{% for buzz in foo %}
<h1>{{ buzz. name_part.title}}
{% for bar in buzz.rozdils %}
<h2>{{ bar.title }}
{% endfor %}
{% endfor %}
Есть ли более элегантный выход из такой ситуации? (миксины?)
.btn
// bootstrap styles
.mybtn
@extends .btn
//..
.mybtn2
@extends .btn
//..
{{ STATIC_URL }}
<!DOCTYPE HTML>
<meta charset="utf-8">
<link href="{% static "bootstrap/css/bootstrap-responsive.css" %}" rel="stylesheet">
<script src="{% static "bootstrap/js/bootstrap.js" %}"></script>
{% load staticfiles %}