简体   繁体   中英

Run DJango server from outside of virtual environment by using script

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!

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

Link

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM