I'm making a web application where the user can render an image with blender. I'm using django as the framework and have it running in a docker environment.
You can render a image with blender console commands like this:
blender -b animation.blend -o //render_ -F PNG -x 1 -a
My question is what would be the best practice to launch console commands from Django?
I know you can add custom commands to the manage.py but not how to launch those.
and more specifically how do I launch an docker container with arguments that includes the blender console.
There's a similar question on Blender stackexchange: https://blender.stackexchange.com/a/1366
I would recommend you using blender as a Python module and not running a separate process since it's harder to control the load on the system and handle errors. How to run the blender as Python module: https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule
However, for the sake of simplicity, you can run the blender
as a command using subprocess
, see examples here: https://docs.python.org/3/library/subprocess.html#subprocess.run
import subprocess
subprocess.run(
["blender", "-b", "animation.blend", "-o", "//render_", "-F", "PNG", "-x", "1", "-a"]
)