我有chatbot在Django框架中的web應用程序。到目前爲止一切正常,但現在,我想使用ajax運行chatbot python腳本並從Javascript文件中調用視圖。我有一個使用REST的API以及python腳本和ajax的視圖來調用該視圖。Django視圖運行python腳本
view.py:
from chat.chatbot1 import main_chatbot
def run_python_script(request):
os.system('python3 main_chatbot.py')
return HttpResponse("OK")
index.js:
function run_chatbot_script(){
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:8000/chatbot/run_python_script/',});
和Python腳本文件夾位於聊天機器人Django項目裏面聊天應用。
的問題是,鑑於無法找到該文件,出現此錯誤:如果是同一個文件夾
例子:
python3: can't open file 'main_chatbot.py': [Errno 2] No such file or directory
使用腳本的完整路徑 - 服務器可能在與腳本不同的文件夾中運行。 – furas
@furas main_chatbot位於聊天應用程序內部名爲chatbot1的文件夾內。寫完整的路徑,它仍然是相同的錯誤視圖無法看到chatbot1文件夾 –