Is it possible to run Ubuntu terminal commands using DJango

I am designing a simple site using DJango and my database is HBase. In some part, I need to save some files to HDFS, such as a video file, and have a URI. But my problem is that I could not find an API to access HDFS through DJango, so I decided to use the Ubuntu terminal command to upload and download data to HDFS. Now I want to know if there is a way to run a terminal command using Django or any other way to access the HDFS API via Django?

+4
source share
2 answers

django make a subprocess call as shown below. Each line in the command must be a line in the list.

import subprocess
subprocess.call(["ls", "-l"])
0
source

You do not need to look for Django implemented libraries, Django is written in python, and python provides libraries for it.

Alternative solution

import subprocess
subprocess.Popen(['python', 'manage.py', 'runserver'])

you can excecute shell commands using subprocess.Popen as well. The difference between the Popen subprocess and the call and how to use them is described here . What is the difference between the Popen subprocess and the call (how can I use them)?

0
source

Source: https://habr.com/ru/post/1653357/


All Articles