Home > Software design >  Django url path is duplicated
Django url path is duplicated

Time:01-20

I am getting a duplicate url pattern from newly added app : http://127.0.0.1:8000/quote/quote/new/

base app urls.py:

urlpatterns = [
path('admin/', admin.site.urls),
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('', include('post.urls')),
path('quote/', include('quote.urls')),   

]

New app urls.py:

urlpatterns = [


    path('quote/new/', QuoteCreateView.as_view(), name='quote-create'),

]

I have tried: path('', include('quote.urls')), in base urls.py but get the same problem.

CodePudding user response:

In your "base app" urls.py you've got this line:

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

In "new app" ("quote app") you've got this line:

path('quote/new/', QuoteCreateView.as_view(), name='quote-create'),

When you include 'quote.urls', each of the URLs is added to the quote/ prefix, which you've set in "base app". In you want your app to create URLs like quote/new, then you should do the following:

in "base app" urls.py:

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

in "new app" (or "quote app") urls.py:

path('new/', QuoteCreateView.as_view(), name='quote-create'),

CodePudding user response:

base app urls.py:
 

urlpatterns = [
     path('quote/', include('quote.urls')),
     ]

New app urls.py:



urlpatterns = [
    path('new/', QuoteCreateView.as_view(), name='quote-create'),
    ]
  •  Tags:  
  • Related