简体   繁体   中英

How to run command line inside a django view?

[Context]

I have a file upload operation in my Django application (on ubuntu server), I have to execute an operation after the user uploaded the file. The tool for that is only available as a npm package (accessible via command line).

  1. What is the recommended solution for this?

Django is is python webframework. So you can use any of the module provided by python. However give a try to subprocess module. This module is a preferred way of running other programs with Python. Take a look.

import subprocess print(subprocess.check_output(['ls','-l']))

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