简体   繁体   English

使用脚本从虚拟环境外部运行 DJango 服务器

[英]Run DJango server from outside of virtual environment by using script

I have created DJango Project inside virtual environment.我在虚拟环境中创建了 DJango 项目。 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 .假设虚拟环境DJangoProject项目名称是Mysite我厌倦了每次运行./manage.py runserver所以我想在登录ubuntu时自动运行服务器。我尝试了很多方法但总是无法访问虚拟路径环境 So help me to run manage.py runserver from outside of virtual environment using bash or shell scripting.所以请帮助我使用 bash 或 shell 脚本从虚拟环境外部运行 manage.py runserver。 any help can be appreciate!任何帮助都将不胜感激!

What are looking for is something like Gunicorn, because runserver is only for development purposes. 寻找的是类似Gunicorn的东西,因为runserver仅用于开发目的。 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. 如果您的项目依赖于虚拟环境,则不能“从虚拟环境外部运行manage.py runserver” ...但是,没有什么可以阻止您编写CD打包到项目根目录的bash脚本,激活virtualenv并启动。开发服务器。

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这在 Ubuntu 中很容易,您只需要创建一个 shell 脚本并从终端中的文件夹运行它: ./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.但首先,您需要通过编写在终端上用于运行 django 服务器的相同命令来创建 shell 脚本。 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.即使此方法可以帮助您运行应用程序,您也不会在终端上看到实际的文件夹访问权限和虚拟环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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