I'm struggling to deploy my django app to railway. The app continues to successfully deploy to Railway, however when visiting the URL of my railway app, I continue to get the error: TemplateDoesNotExist at /index.html. Since I'm using react with Django, I understand the process of serving the static files from react after they are built, and when running this project locally, everything has been working fine, the issue only started once I began to deploy to Railway. For reference, the folder where I've stored my reactapp is called 'reactapp'. Here are the key components of my manage.py file:
ALLOWED_HOSTS = ["myprojecturl.railway.app", "127.0.0.1"]
CORS_ALLOWED_ORIGINS = [
"http://127.0.0.1:8000/home/",
"myprojecturl.railway.app"
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'api/templates/api'),
BASE_DIR / 'reactapp/build',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / 'reactapp/build/static',
]
My main urls.py file:
path('', TemplateView.as_view(template_name='index.html'))
Here was the warning I received in my deployment logs from Railway:
?: (staticfiles.W004) The directory '/app/reactapp/build/static' in the STATICFILES_DIRS setting does not exist.
I'm confused because this project works fully well locally, but the problems keep arising when deploying to Railway. Any help is appreciated, Thanks!
Edit:
After continuing to experiment, I think there may be an issue since I'm using my github repository to deploy. In my github reactapp, the build file is listed in git ignore, meaning it doesn't show up in the repo, so maybe this is why the project cannot find the path. Should I remove this, or try something else?