0

every time I need to start a Django server, I have to do the following:

cd to some directory
source env/bin/activate
python manage.py run_gunicorn 0.0.0.0:8000

How could I simplify this process by creating a script that would start the server once executed.

I tried to create .sh script with, but I failed to change Python environment with source command.

Then I tried to create .py file and execute commands with os.system(), but virtualenv did not seem to have been initiated.

1
  • 1
    Could you be more specific about the error you get when source env/bin/activate fails ? Commented Mar 6, 2012 at 12:25

1 Answer 1

1

I would do it as a shell function rather than as a script:

djangoserver() {
    cd $1
    source env/bin/activate && python manage.py run_gunicorn 0.0.0.0:8000
}

This should be functionally equivalent to running it at the command line.

You could put the same lines inside a shell script, in which case the 'source' command would be local to the shell script. That would probably be a good thing, as long as there aren't variables that you want to keep in scope after you run the script.

Sign up to request clarification or add additional context in comments.

1 Comment

If you call the python interpreter from the virtualenv, you don't need to use the 'activate' script: some_directory/env/bin/python manage.py run_gunicorn 0.0.0.0:8000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.