1

register.html is not accessible on 'register/' url

tried changing url to '' and webpage is accessible but not on 'register/'

projects urls.py

 from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('login/',include('login.urls')),
    path('admin/', admin.site.urls),
]

apps urls.py

 from django.urls import path
from . import views

urlpatterns = [
    path('',views.indexView, name = "home"),
    path('dashboard/', views.dashboardView, name="dashboard"),
    #path('login/',),
    path('register/',views.registerView, name="register_url"),
    #path('logout/',),
]

views.py

 from django.shortcuts import render

def indexView(request):
    return render(request,'index.html')

def dashboardView(request):
    return render(request,'dashboard.html')

def registerView(request):
    return render(request,'register.html')

templates/register.html

2 Answers 2

1

Either you type login/ before evry URL pattern of apps urls.py file while testing URL.

or

You should include url mapping of apps urls.py in main urls.py This might help you.

from django.contrib import admin
from django.urls import path,include


urlpatterns = [
    path('',include('apps.urls')), #put you app name here
    path('admin/', admin.site.urls),
]

apps urls.py

 from django.urls import path
from . import views

urlpatterns = [
    path('',views.indexView, name = "home"),
    path('dashboard/', views.dashboardView, name="dashboard"),

    path('register/',views.registerView, name="register_url"),

]

This will work and you can add login/ url mapping inside the apps urls.py. This type of flow will make it easy to understand .

Sign up to request clarification or add additional context in comments.

5 Comments

sry i mention as apps bt actual that app name is itself login
if your app name is login then just do this simple edit in your code, replace 'login/' in main urls.py with just "" bank so url name will not bother you .
otherwise you have write login before every url name of apps urls.py file.
the reason itis not accessible on 'register/ because it is accessible on 'login/register/'
ty bro its working fine :-) hv a nice day ...thank u for answering !!!
1

Use url_name for URL calling:

{% url 'register_url' %} 

This will directly search for 'register_url' in the project and will return the path. url_name must be unique so make sure your url_name is uniquely defined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.