Running Django Virtual Environment in Grunt

Based on the background of the JS / Node development, I like to use Grunt for my automation. For a recent project, I took the child Django to understand how it works, but still wanted to integrate Grunt for my workflow.

I am currently running my Django server through Grunt using the spawn-shell module. This works fine, but I also use the virtualenv setup, and would also like to start this through Grunt.

The command that I run to start the virtual environment is:

source ./venv/bin/activate

Which works fine from the command line of the terminal, as it is. However, executing this command from the grunt or grunt exec command line does nothing. I get no errors from Grunt (it says it works and then runs without errors), but nothing starts.

The grunt exec command looks like this:

exec: {
  start: {
    cmd: function() {
      return "source ./venv/bin/activate";
    }
  }
}

And shell command:

shell: {

  start: {
    command: 'source ./venv/bin/activate',
    options: {
      stdout: true
    }
  }
}

Any ideas on how to make this work? Or is this not possible, and should I just resort to entering the command manually at startup?

+4
source share
1 answer

Usually, trying to get another tool function to start django when using virtualenv, the normal thing is to perform one of the following actions in one command:

  • activate virtualenv
  • run the desired command.

therefore it ends:

. ${VIRTUALENVHOME}/bin/activate && ${PROJECTROOT}/manage.py runserver 0:8000

This is mainly done using Fabric, Ansible, and any other automation tool.

edit: of course you will supply values ​​for variables VIRTUALENVHOMEandPROJECTROOT

+5
source

Source: https://habr.com/ru/post/1528175/


All Articles