Django call_command()未运行外部命令

时间:2019-12-19 12:12:02

标签: python django django-views

我无法运行使用call_command()运行外部脚本的命令

这是我的代码:

from django.core import management

@login_required
def play_redirect(request):
    management.call_command('runscript', 'runnerscript')
    return HttpResponse('Please wait while we redirect you...')

runscript是从django-extensions模块获得的特殊命令,它运行一个脚本,该脚本具有用vpython制作的游戏,但是每次我运行此脚本时,都会得到与线程相关的RuntimeError。

这是确切的错误:

RuntimeError at /bloxors/play/
There is no current event loop in thread 'Thread-1'.
Request Method: GET
Request URL:    http://127.0.0.1:8000/bloxors/play/
Django Version: 2.2.2
Exception Type: RuntimeError
Exception Value:    
There is no current event loop in thread 'Thread-1'.
Exception Location: C:\Users\Dps\AppData\Local\Programs\Python\Python37-32\lib\asyncio\events.py in get_event_loop, line 644
Python Executable:  C:\Users\Dps\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.2
Python Path:    
['C:\\Users\\Dps\\Desktop\\bloxnsims\\website',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Dps\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\Pythonwin']

在此方面可能提供的任何帮助,将不胜感激!

0 个答案:

没有答案