Reputation: 1039
After using Grunt for a couple of projects I decided to give Gulp a try.
Most of the projects we work on are Python based, and the way we usually run them from the command line is: 'python manage.py runserver'
With Grunt, i found the grunt-bg-shell plugin, and was able to run my command like this:
// see: https://npmjs.org/package/grunt-bg-shell
bgShell: {
_defaults: {
bg: true
},
runDjango: {
cmd: 'python <%= paths.manageScript %> runserver 0.0.0.0:<%= port %>'
//cmd: 'python <%= paths.manageScript %> runserver'
}
}
grunt.registerTask('serve', [
'bgShell:runDjango',
'watch'
]);
Unfortunately, so far i have been unable to find a similar plugin for Gulp. I've tried gulp-shell, gulp-run, gulp-exec, all to no avail. With most im able to print my string on the console, but i havent been able to run the actual command.
Any ideas ?
Upvotes: 11
Views: 3464
Reputation: 11
It's a old question, but a good alternative is django-gulp (https://pypi.python.org/pypi/django-gulp/2.0.0). It will run your gulp default task when you run the runserve command (gulpfile needs to be in the same directory of manage.py).
Upvotes: 1
Reputation: 193
You can do this:
var process = require('child_process');
gulp.task('flask', function(){
var spawn = process.spawn;
console.info('Starting flask server');
var PIPE = {stdio: 'inherit'};
spawn('python', ['manage.py','runserver'], PIPE);
});
This spawns a new child process running 'python manage.py runserver' and passes the output of flask to gulp output stream.
Upvotes: 8
Reputation: 1804
I'm using gulp-shell to run a Flask server. I believe it should work the same way with Django:
var shell = require('gulp-shell');
gulp.task('flask', shell.task(['. env/bin/activate && python my_script.py']));
Did you use another syntax ... ?
Upvotes: 8