Page Not Found (404) for /accounts/login/ on Railway (Works Fine Locally
supercool27
FREEOP

8 months 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.

link emoji Live URL:

https://server-production-7653.up.railway.app/accounts/login

white_check_mark emoji My Project Structure:

pgsql

CopyEdit

project-root/ ├── mysite/ │ └── urls.py ├── accounts/ │ ├── urls.py │ └── views.py ├── templates/ │ └── accounts/ │ └── login.html

open_file_folder emoji Code Snapshots:

mysite/urls.py:

python

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:

python

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:

python

CopyEdit

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ BASE_DIR / "templates" ], 'APP_DIRS': True, ... } ]

mag emoji 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.

exclamation emoji Suspicions:

  • Template not being picked up in production?

  • Git may not have tracked the templates/ folder earlier (already forced git add -f templates/).

  • Could Railway have cached an old build?

sos emoji 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!

$10 Bounty

4 Replies

idiegea21
HOBBY

8 months 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.


sim
FREE

7 months ago

I opened your url and it shows this

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

admin/
The current path, accounts/login, didn’t match any of these.

That means only the /admin route is set up

Share how and where you are defining your routes



supercool27
FREEOP

7 months ago

https://hrmdjango-production.up.railway.app/accounts/login/ i have successfully setup my first page with django. if anybody need it or help from me to host i can. Thank you for giving support.


Loading...