Configure Django to use Render disk

Hi,

How do I configure Django so it uses the Render disk?

From Django, I can’t seem to write to a Render disk mounted on /var/data
“sudo chmod” is not possible, since the shell runs under Render and not root

Thanks!

Hi @frank , you won’t be able to sudo chmod the mount point for your disk (/var/data), but the mount point will already be writable. Are you able to use the disk without running sudo chmod?

Hi Dan,

Thanks again for your reply.

Manually I can, but writing failed on deploy when I tried setting /var/data/ as the BASE_DIR in Django settings.

(Trying to get Django to store and serve file uploads on Render)

Thank you!

I’m not sure what Django is doing, but if it’s trying to do something to the directory itself like the chmod rather than writing to the directory, you might need to first make some directory inside of /var/data like /var/data/django so Django can fully control that directory.

Thanks for your suggestion,

Tried using a subdirectory (/var/data/files) as the settings path for Django upload storage with no luck.

OSError: [Errno 30] Read-only file system: ‘/var/data’
Feb 18 02:46:41 PM ==> Build failed :disappointed:

Manually I can write there, but I’m not sure how to let Django do the same.
Current problem is that file uploads disappear after a new deploy because they’re not written to the separate Render disk.

Thanks for the additional logs :slight_smile: Seeing that this is occurring during the build phase makes the problem clearer to me:

Persistent disks are only mounted at runtime, not at build time. At build time, your build script should only be creating files in the current directory at the start of the build (/opt/render/project/src). The files in that directory are bundled as a single asset used to deploy to your service instances.

If you need to generate files during build-time, they should be put in that directory. If you need build-time assets to be present in your persistent disk, they must be moved during run-time, since that is when the persistent disk is present.

We also have a Getting Started with Django on Render doc that may be useful as a reference for configuration help.

One also note, that you will need to keep gunicorn in mind, it might be helpful to run gunicorn --pythonpath app app