Marco Fernandes
Marco Fernandes

Reputation: 553

Django Url Pattern Not Being Found

I followed a tutorial to allow users to register an account but the url path does not seem to be found. It allows me to access 127.0.0.1:8000/accounts/signup but not 127.0.0.1:8000/signup when I have set the name for it.

I tried changing the urlpatterns from a path to a url method but that didn't solve the problem.

my file structure is as follows:

App:
   accounts:
           urls.py
           views.py
           ...
   Server:
         settings.py
         urls.py
         ...
   templates:
            registration:
                        login.html
            base.html
            home.html
            signup.html
   manage.py

In my Server\urls.py I have

from django.contrib import admin
from django.urls import path, include
from django.views.generic.base import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('accounts/', include('accounts.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('', TemplateView.as_view(template_name='home.html'), name='home'),
]

In my accounts\urls.py I have

from django.urls import path

from . import views


urlpatterns = [
    path('signup/', views.SignUp.as_view(), name='signup'),
]

The error I get is

Using the URLconf defined in Server.urls, Django tried these URL patterns, in this order:
   admin/
   accounts/
   accounts/
   [name='home']
The current path, signup, didn't match any of these.

I'm not too sure what is going on since I'm still sort of new to Django and busy learning as I go along.

Upvotes: 0

Views: 3403

Answers (1)

IVNSTN
IVNSTN

Reputation: 9299

path('accounts/', include('accounts.urls')),

means that all urls from accounts.urls are supposed to be prefixed with accounts/. If that's not what you want - edit this to

path('/', include('accounts.urls')),

and accounts.urls will be treated as top-level urls.

Upvotes: 8

Related Questions