Gulp Task for Django Server

I am trying to create a task to run my Django backend.
It took me quite a while to solve these two problems:

  • Find the right way to activate virtualenv
  • Get the managing server manage.py for output to standard output

After searching for the watch, I put together a solution.
Hope this saves someone a lot of time and frustration.

+4
source share
1 answer

The gulp task below, written in coffeescript, will launch the Django backend:

exec = require('child_process').exec

gulp.task 'serve:backend', ->
  proc = exec 'source bin/activate; PYTHONUNBUFFERED=1 ./manage.py runserver'
  proc.stderr.on 'data', (data) -> process.stdout.write data
  proc.stdout.on 'data', (data) -> process.stdout.write data

You can run the task using gulp serve:backend
Note:

  • You do not need to install any Node packages built-in child_process.
  • exec spawn,
  • stdout, stderr,
  • PYTHONUNBUFFERED (grmbl)
+9

All Articles