Django App Not Loading Environment Variables in settings.py at Startup

sterneesr
FREE

a month ago

Hello Railway Support Team,

I am experiencing a critical issue where my Django application is not reading environment variables correctly in settings.py during the startup/deployment process, even though the variables are available at runtime.

What I have confirmed:

  1. I have created a test view (/products/test-upload/) that uses the cloudinary library to directly upload a file. This view works perfectly, which proves my CLOUDINARY_... secret variables are correct and the server has network access to the Cloudinary API.

  2. I have created a diagnostic view (/products/check-storage/) to check the value of DEFAULT_FILE_STORAGE. It consistently shows "FileSystemStorage", meaning my production settings are being ignored.

  3. I have tried multiple if/else conditions in settings.py (checking DEBUG, checking a custom DJANGO_ENV variable) to switch between production and development settings, but the else block (development) is always chosen.

  4. Most importantly, I even removed all if/else logic and hardcoded DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage', but my diagnostic view still reports "FileSystemStorage".

This last point proves that the code in my settings.py file is being ignored or overridden during the application startup process on your platform. I have added print() statements to my settings.py file, and the deployment logs confirm that the variables are not being read as expected at that stage.

Could you please investigate why the environment variables might not be available to the Django settings.py module at the exact moment of startup? Is there a caching mechanism or a specific startup procedure I need to be aware of?

Thank you.

$10 Bounty

4 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


25 days ago

Howdy!
I'm not extremely familiar with Django personally however a quick peruse online gave a bit of info.

On that, is your CLOUDINARY_... variable being set in the Variables tab of Railway? If the test route /products/test-upload is pulling correctly that is an issue with your settings.py which is failing to correctly read env vars.

Would love to nail down where the pain point is so any info is good info!


sterneesr
FREE

25 days ago

Everything is set correctly. i debugged everything but still no use. everything is set perfectly


sterneesr

Everything is set correctly. i debugged everything but still no use. everything is set perfectly

25 days ago

Well I would like some more info.
Can I hear some about the project itself and what it is?

And to clarify, pulling CLOUDINARY_... from the environment variables does work right?