Reputation: 11
ERROR :Using the URLconf defined in crm1.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
products/ [name='products']
customer/<str:pk_test>/ [name='customer']
create_order/<str:pk>/ [name='create_order']
update_order/<str:pk>/ [name='update_order']
delete_order/<str:pk>/ [name='delete_order']
The current path, customer, didn't match any of these. even when i run this.....accounts/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home, name='home'),
path('products/',views.products, name='products'),
path('customer/<str:pk_test>/',views.customer,name='customer'),
path('create_order/<str:pk>/',views.createOrder,name='create_order'),
path('update_order/<str:pk>/',views.updateOrder,name='update_order'),
path('delete_order/<str:pk>/',views.deleteOrder,name='delete_order'),
]
all path are running correctly and even when i run http://127.0.0.1:8000/customer/2
it runs properly....but when i run http://127.0.0.1:8000/customer/ error out
actually
/<str:pk_test>/
kind of path create problem i dont know
Upvotes: 1
Views: 390
Reputation: 4095
Well there is not route for customer only. So, add this line in your urls.py
:
path('customer/',views.customer,name='customer-only'),
*Note:- Add the line above the another code. Like:-
path('customer/',views.customer,name='customer-only'),
path('customer/<str:pk_test>/',views.customer,name='customer'),
Okay, as your views.py
needs argument, you have to do:
def customer(request, pk_test=None):
customer=Customer.objects.get(id=pk_test)
orders=customer.order_set.all()
order_count =orders.count()
context={'customer':customer,'orders':orders,'order_count':order_count}
return render(request,'accounts/customer.html',context)
Upvotes: 1