django-allauth 127.0.0.1:8000/accounts/login/ throws "The current path didn’t match any of these" but works for localhost:8000/accounts/login/

I have created a new Django project and added a couple of packages, including the django-allauth package. In my urls.py I have the following:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('ckeditor5/', include('django_ckeditor_5.urls')),
    path('accounts/', include('allauth.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Now when I start runserver, it says

Starting development server at http://127.0.0.1:8000/

If I go to http://127.0.0.1:8000/admin/, everything is fine and I do get the login form. But if I go to http://127.0.0.1:8000/accounts/login/, I get redirected to http://127.0.0.1:8000/accounts/profile/ with the following error:

Page not found (404)

Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/profile/

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

  1. admin/
  2. ckeditor5/
  3. accounts/ signup/ [name=‘account_signup’]
  4. accounts/ login/ [name=‘account_login’]
  5. accounts/ logout/ [name=‘account_logout’]
  6. accounts/ password/change/ [name=‘account_change_password’]
  7. accounts/ password/set/ [name=‘account_set_password’]
  8. accounts/ inactive/ [name=‘account_inactive’]
  9. accounts/ email/ [name=‘account_email’]
  10. accounts/ confirm-email/ [name=‘account_email_verification_sent’]
  11. accounts/ ^confirm-email/(?P[-:\w]+)/$ [name=‘account_confirm_email’]
  12. accounts/ password/reset/ [name=‘account_reset_password’]
  13. accounts/ password/reset/done/ [name=‘account_reset_password_done’]
  14. accounts/ ^password/reset/key/(?P[0-9A-Za-z]+)-(?P.+)/$ [name=‘account_reset_password_from_key’]
  15. accounts/ password/reset/key/done/ [name=‘account_reset_password_from_key_done’]
  16. accounts/ social/
  17. accounts/ google/
  18. ^media/(?P.*)$

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

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

However the http://localhost:8000/accounts/login/ path works fine and I see the authentication page. Why is it that 127.0.0.1:8000 doesn’t work while localhost:8000 does? Thank you for your help!

I don’t have a specific answer to your particular question regarding django-allauth, however, what I can tell you is that while localhost might refer to the ip address 127.0.0.1, they are not the same domain in the context of the browser.

Various security-related issues (cookies, etc) are segregated by domain, and so if a cookie is issued from 127.0.0.1, a site identified by localhost will not have access to that cookie.

(Yes, “localhost”, as a host name, can be mapped to anything in the 127/8 subnet and still be a valid loopback address - or it could be mapped to an external address - all possibilities for which a browser must be able to handle appropriately.)

So, in general terms, if you’ve got something that works on localhost but not on 127.0.0.1, then that implies that some package cares about the difference and is configured for one but not the other.

Thank you very much for your answer. It helped me to figure out the cause of the problem. I was logged in as the admin and because of that accounts/login was not available. As you said, localhost is not the same thing and that is why admin status had no effect.