I have chatbot web application in Django framework. So far everything is working, but now, I want to run the chatbot python script using ajax and calling the view for it from the Javascript file. I have an API using REST and the view for the python script and the ajax to call that view.
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/',});
and the python script folder is located in the chat app inside the chatbot django project.
The problem is that the view can't find the file and this error appears:
python3: can't open file 'main_chatbot.py': [Errno 2] No such file or directory