Railway app not working in production

Hi all…

I’m struggling to troubleshoot my deployed site…

Everything is working fine running locally, where I’m using an sqlite database. I created a postgres database on railway alongside the app, which is intended to be used in production. I have environment variables set up for the postgres database (DATABASE_URL), along with SECRET_KEY & also CLOUDINARY_URL as I’m using cloudinary to serve my static files.

In production the homepage loads as expected, but as soon as I try to navigate to any other pages it throws a 400 bad request error.

I’ve attached my entire settings.py for reference

Any pointers will be much appreciated!

from pathlib import Path
import os
import dj_database_url

if os.path.exists('env.py'):
    import env

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['backtofront-production.up.railway.app', '']
CSRF_TRUSTED_ORIGINS = ['https://*.railway.app']

# Application definition




ROOT_URLCONF = 'backtofront.urls'

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR, 'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

WSGI_APPLICATION = 'backtofront.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / 'db.sqlite3',
        'default': dj_database_url.parse(

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/



USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'

STATICFILES_STORAGE = 'cloudinary_storage.storage.StaticHashedCloudinaryStorage'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


from the CLI I can see that when I try to navigate to another page on the site it throws: ‘“GET /blog/ HTTP/1.1” 400 143’

this seems to correspond to the postgres database logs ‘LOG: could not receive data from client: Connection reset by peer’ immediately after

The connection does work to some degree though as I have managed to create an admin and add a post to the database.

Really struggling to find any useful info/possible reasons for this, my only thoughts are maybe something to do with static files being served from Cloudinary? or the way that is configured.

Again any info would be much appreciated!