从 bash 脚本运行“python manage.py runserver”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6369054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:11:45  来源:igfitidea点击:

Run "python manage.py runserver" from a bash script

pythondjangobashseleniumhudson

提问by Sorin M

I want to run "python manage.py runserver" from a bash script

我想从 bash 脚本运行“python manage.py runserver”

First if I wanted to run from a terminal "python manage.py runserver &" but it doesn't work. I found the fix for this in (https://code.djangoproject.com/changeset/16327). Manually in a terminal running "python manage.py runserver &" works fine. I've added in a bash script "python manage.py runserver &" but it doesn't start the server.

首先,如果我想从终端“python manage.py runserver &”运行但它不起作用。我在 (https://code.djangoproject.com/changeset/16327) 中找到了解决方法。在终端中手动运行“python manage.py runserver &”工作正常。我在 bash 脚本中添加了“python manage.py runserver &”,但它没有启动服务器。

Error:
File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/django/utils/autoreload.py", line 137, in main
    reloader(main_func, args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/django/utils/autoreload.py", line 110, in python_reloader
    reloader_thread()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/django/utils/autoreload.py", line 89, in reloader_thread
    ensure_echo_on()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/django/utils/autoreload.py", line 77, in ensure_echo_on
    attr_list = termios.tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')

回答by Jiaaro

The problem is probably that hudson is not running as your user... you could run

问题可能是 hudson 没有以您的用户身份运行……您可以运行

source /home/your_user/.bashrc && django_serve 

to make it run that alias, but I think you'll probably need to switch users

让它运行那个别名,但我认为你可能需要切换用户

-- or --

- 或者 -

have hudson run the dev server from it's own checkout of the source

让 hudson 从它自己的源代码检出运行开发服务器

Edit: Looking at your erro though, I think this may solve your problem:

编辑:虽然看着你的错误,我认为这可能会解决你的问题:

instead of

代替

python manage.py runserver

try adding the --noreloadflag to disable the auto reloader

尝试添加--noreload标志以禁用自动重新加载器

python manage.py runserver --noreload

回答by sultan

I use alias to start django server. May be can help)

我使用别名来启动 django 服务器。可能会有所帮助)

Just add alias django_serve="python manage.py runserver &"at the end of your ~/.bashrcor ~/.profile.

只需alias django_serve="python manage.py runserver &"在您的~/.bashrcor末尾添加~/.profile

Also you create .bash_aliasesand place your aliases into this file and execute it before you make any actions like

您还可以创建.bash_aliases别名并将其放入此文件中,并在执行任何操作之前执行它,例如


if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi