4 days ago
I have deployed a Django app to Railway, and while everything works fine in my local development server, the /accounts/login/
page throws a 404 error on the live server.
Live URL:
https://server-production-7653.up.railway.app/accounts/login
My Project Structure:
CopyEdit
project-root/ ├── mysite/ │ └── urls.py ├── accounts/ │ ├── urls.py │ └── views.py ├── templates/ │ └── accounts/ │ └── login.html
Code Snapshots:
mysite/urls.py
:
CopyEdit
from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('accounts.urls')), ]
accounts/urls.py
:
CopyEdit
from django.urls import path from django.contrib.auth import views as auth_views urlpatterns = [ path('login/', auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'), ]
settings.py
:
CopyEdit
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ BASE_DIR / "templates" ], 'APP_DIRS': True, ... } ]
What I’ve Tried:
Confirmed the
templates/accounts/login.html
exists and renders locally.Verified all files are pushed to GitHub.
Confirmed Railway is deploying the latest commit.
Tried accessing
/accounts/
and/accounts/login/
— both give 404.No errors during deployment, and
/admin/
works fine.
Suspicions:
Template not being picked up in production?
Git may not have tracked the
templates/
folder earlier (already forcedgit add -f templates/
).Could Railway have cached an old build?
Request:
Could anyone help me debug what I might be missing or doing wrong? Any tips to ensure the app correctly routes /accounts/login/
in production?
Thanks in advance!
1 Replies
2 days ago
Your /accounts/login/
page works locally but gives a 404 on Railway likely because the templates/accounts/login.html
file wasn't included in your Git repo or wasn't deployed correctly.
Make sure that login.html is actually tracked and pushed
git add -f templates/accounts/login.html
git commit -m "Add login template"
git push
Then you come to railway and clear your build cache and then you redeploy.
if it still fails, check your railway logs and drop the error logs for better debugging.