3

I have created DJango Project inside virtual environment. Let's say virtual environment DJangoProject project name is Mysite I am tired of running ./manage.py runserver everytime so that I wanted to automate running server when I was logged into ubuntu.I tried many ways but was always failing to access the path of virtual environment. So help me to run manage.py runserver from outside of virtual environment using bash or shell scripting. any help can be appreciate!

Ramsk
  • 171
  • 2
  • 11

3 Answers3

3

What are looking for is something like Gunicorn, because runserver is only for development purposes. This is detailed tutorial for you to use

Link

kmcodes
  • 807
  • 1
  • 8
  • 20
1

You can't "run manage.py runserver from outside of virtual environment" if your project relies on a virtual environment... But nothing prevents you from writing a wrapper bash script that cd into your project's root, activate the virtualenv and launch the dev server.

This being said, I really don't see the point - and I even see a couple reasons to not do so, the first one being that you definitly want to keep the terminal where you run your dev server from opened so you can read all the logs in real time.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
  • We can put bash script file in startup files right? that I don't think need to keep terminal open everytime – Ramsk Dec 06 '17 at 12:04
  • @Ramuk you can launch just any executable at startup, yes. But from experience what you're trying to do is a bad idea, as you'll find out by yourself. – bruno desthuilliers Dec 06 '17 at 12:06
0

That's easy in Ubuntu you just need to create a shell script and run it from it's folder in the terminal as : ./shellscriptname.sh

but for that first you need to create the shell script by writing the same commands used on terminal to run the django server. Example:

echo Hello Sangeeth
echo Lets start the app
cd myapp
cd venv
source bin/activate
cd ..
cd myapp
python manage.py runserver

even though this method helps you run the app , you wont be seeing the actual folder access and virtual environment on the terminal.

Sangeeth Joseph
  • 152
  • 1
  • 8