Environment variable not working during deploy
odissine
FREEOP

a month ago

During deployment it seems my env variable are not getting.

Here is a sample of my settings

I can't get any variable set up in VARIABLE from Railway !

Is there something I can do ? Something I missed ?

Thanks for your help

from pathlib import Path

from urllib.parse import urlparse

from django.urls import reverse_lazy

from django.utils.translation import gettext_lazy as _

import os

import environ

import certifi

os.environ["SSL_CERT_FILE"] = certifi.where()

os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()

BASE_DIR = Path(file).resolve().parent.parent

env = environ.Env()

environ.Env.read_env(BASE_DIR / ".env")

CONTENT_DIR = os.path.join(BASE_DIR, 'content')

SECRET_KEY = os.environ.get('SECRET_KEY', env('SECRET_KEY', default=None))

DEBUG = os.environ.get('DJANGO_DEBUG', env('DEBUG', default='False')) == 'True'

print(DEBUG)

[...]

Database

if os.getenv("DJANGO_ENV") == "PRD":

print("PROD")

DATABASES_PG = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql',

        'NAME': os.getenv('POSTGRES_DB', 'default'),

        'USER': os.getenv('POSTGRES_USER', 'user'),

        'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'password'),

        'HOST': os.getenv('POSTGRES_HOST', 'localhost'),

        'PORT': os.getenv('POSTGRES_PORT', '5432'),

        'OPTIONS': {

            'sslmode': 'require',  # ✅ important !

        },

    }

}

DATABASES_LOCAL = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': BASE_DIR / 'db.sqlite3',

    }

}

else:

print("LOCAL")

DATABASES_LOCAL = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': BASE_DIR / 'db.sqlite3',

    }

}

DATABASES_PG= {

    'default': {

        'ENGINE': 'django.db.backends.postgresql',

        'NAME': os.getenv('POSTGRES_DB', 'default'),

        'USER': os.getenv('POSTGRES_USER', ''),

        'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''),

        'HOST': os.getenv('POSTGRES_HOST', 'localhost'),

        'PORT': os.getenv('POSTGRES_PORT', '5432'),

        'OPTIONS': {

            'sslmode': 'disable',  # ✅ important !

        },

    }

}

DATABASES = DATABASES_PG

[...]

Solved$10 Bounty

Pinned Solution

When you added variables to your service, did you apply the changes (it appears at the top of the page when you make changes)?

image.png

Attachments

2 Replies

Railway
BOT

a month ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway • 27 days ago


When you added variables to your service, did you apply the changes (it appears at the top of the page when you make changes)?

image.png

Attachments


odissine
FREEOP

a month ago

Oh ... my ... god ... I'm so sorry but you right :) I didn't notice this infomrmation and Deploy for me was ... deploy image with changes ... not deploy variable in Project ;)

Thanks so so much it's working now


Status changed to Solved 0x5b62656e5d • 16 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...