Am building a CRM application and thing was going fine until I got this roadblock Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/leads//update/
I have tried tweaking the templates and even the view file but to no avail, Here are the views files for the CRUD aspect
class LeadListView(ListView):
template_name = 'lead_list.html'
queryset = Lead.objects.all()
context_object_name = 'leads'
class LeadDetailView(DetailView):
template_name = 'leads/lead_detail.html'
queryset = Lead.objects.all()
context_object_name = 'leads'
class LeadCreateView(CreateView):
template_name = 'leads/lead_create.html'
form_class = LeadModelForm
def get_success_url(self):
return reverse('leads:lead_list')
class LeadUpdateView(UpdateView):
template_name = 'leads/lead_update.html'
form_class = LeadModelForm
queryset = Lead.objects.all()
def get_success_url(self):
return reverse('leads:lead_list')
And here is the HTML template for detail view
<div class="lg:w-1/2 w-full lg:pr-10 lg:py-6 mb-6 lg:mb-0">
<h2 class="text-sm title-font text-gray-500 tracking-widest">LEAD</h2>
<h1 class="text-gray-900 text-3xl title-font font-medium mb-4">{{ leads.first_name }} {{ leads.last_name }}</h1>
<div class="flex mb-4">
<a href="{% url 'leads:lead_detail' leads.pk %}" class="flex-grow text-indigo-500 border-b-2 border-indigo-500 py-2 text-lg px-1">
Overview
</a>
<a class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
Reviews
</a>
<a href="/leads/{{ lead.pk }}/update/" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
Update Details
</a>
</div>
<p class="leading-relaxed mb-4">Fam locavore kickstarter distillery. Mixtape chillwave tumeric sriracha taximy chia microdosing tilde DIY. XOXO fam inxigo juiceramps cornhole raw denim forage brooklyn. Everyday carry +1 seitan poutine tumeric. Gastropub blue bottle austin listicle pour-over, neutra jean.</p>
<div class="flex border-t border-gray-200 py-2">
<span class="text-gray-500">Age</span>
<span class="ml-auto text-gray-900">{{ lead.age }}</span>
</div>
<div class="flex border-t border-gray-200 py-2">
<span class="text-gray-500">Size</span>
<span class="ml-auto text-gray-900">Medium</span>
</div>
<div class="flex border-t border-b mb-6 border-gray-200 py-2">
<span class="text-gray-500">Quantity</span>
<span class="ml-auto text-gray-900">4</span>
</div>
<div class="flex">
<span class="title-font font-medium text-2xl text-gray-900">$58.00</span>
<button class="flex ml-auto text-white bg-indigo-500 border-0 py-2 px-6 focus:outline-none hover:bg-indigo-600 rounded">Button</button>
<button class="rounded-full w-10 h-10 bg-gray-200 p-0 border-0 inline-flex items-center justify-center text-gray-500 ml-4">
<svg fill="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="w-5 h-5" viewBox="0 0 24 24">
<path d="M20.84 4.61a5.5 5.5 0 00-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 00-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 000-7.78z"></path>
</svg>
</button>
</div>
</div>
And this is for the update view
div class="lg:w-1/2 w-full lg:pr-10 lg:py-6 mb-6 lg:mb-0">
<h2 class="text-sm title-font text-gray-500 tracking-widest">LEAD</h2>
<h1 class="text-gray-900 text-3xl title-font font-medium mb-4">{{ leads.first_name }} {{ leads.last_name }}</h1>
<div class="flex mb-4">
<a href="{% url 'leads:lead_detail' lead.pk %}" class="flex-grow text-indigo-500 border-b-2 border-indigo-500 py-2 text-lg px-1">
Overview
</a>
<a class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
Reviews
</a>
<a href="/leads/{{ lead.pk }}/update/" class="flex-grow border-b-2 border-gray-300 py-2 text-lg px-1">
Update Details
</a>
</div>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
<a href="{% url 'leads:lead_delete' lead.pk %}" class="mt-3 flex ml-auto text-white bg-indigo-500 border-0 py-2 px-6 focus:outline-none hover:bg-indigo-600 rounded">
Delete
</a>
</div>
And I found nothing wrong here with the urls.py
file
from django.urls import path
from .views import (
lead_list, lead_detail, lead_create, lead_update, lead_delete,
LeadListView, LeadDetailView, LeadCreateView, LeadUpdateView
)
app_name = 'leads'
urlpatterns = [
path('', LeadListView.as_view(), name='lead_list'),
path('<int:pk>/', LeadDetailView.as_view(), name='lead_detail'),
path('<int:pk>/update/', LeadUpdateView.as_view(), name='lead_update'),
path('<int:pk>/delete/', lead_delete, name='lead_delete'),
path('create/', LeadCreateView.as_view(), name='lead_create'),
]
Below is the link that is broken and where am I trying to get to
lead.pk
could be null causing the double slash, so you can try and figure out why that is.lead
with pluralleads
in the templates and view functions.