[Answered ]-Url getting duplicated in django: sign/sign/

1πŸ‘

βœ…

The duplicate sign/ appeared because you define two URLs that maps the sign_up_in view.

The first one is on the project level urls.py:

urlpatterns = [
    ...
    path('sign/', include("main.urls")),
]

This pattern will also "include" the urls from your app urls.py.

urlpatterns = [
   ...
   path("sign/", views.sign_up_in, name = "sign_up_in") 
]

So, whenever you call the sign_up_in URL in the template the URL will show the full path based on how you defined your URL pattern. In your case it is

sign/ <-- from your project urls.py
     sign/ <--- from your app urls.py

# output:
sign/sign/

In order for this to work properly, you need to remove the path('sign/', include("main.urls")).

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

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

So whenever you have to define a new URL in your main app urls.py, do not repeat it in your project-level URLs to avoid unwanted results.

NOTE: Your main.urls will always start on leading / so it is wise to
omit any leading / in your main app urls.py whenever you define new
URLs.

πŸ‘€Shift 'n Tab

0πŸ‘

In your app urls.py change

path("sign/", views.sign_up_in, name = "sign_up_in")

to

path("", views.sign_up_in, name = "sign_up_in")

You alreday defined "sign/" in your main urls.py so every url from this app will start with sign/*

πŸ‘€ViLuWi

0πŸ‘

    urlpatterns = [
        path('admin/', admin.site.urls),
        path('', include("main.urls")),
        path('sign/', include("main.urls")), #remove this 
    ]

You already included main.urls once

πŸ‘€lucutzu33

Leave a comment