简体   繁体   中英

Is it possible to run ubuntu terminal commands using DJango

I am designing a simple website using DJango and my database is HBase. In some Part I need to save some files on HDFS, for example video file, and have it's URI. But my problem is I couldn't find any API for accessing HDFS through DJango so I decided to use ubuntu terminal command to upload and download data on HDFS. Now I want to know is there any way to run terminal command using Django or any other way to access HDFS API through Django?

have django make a call to a subprocess like the one below. each string in the command should be a string in a list.

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

You don't need to search for Django implemented libraries, Django is written in python and python is providing libraries for it.

An alternative solution

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM